Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saquibtmf/a1c860e76627365efdb44d6540ffeb36 to your computer and use it in GitHub Desktop.
Save saquibtmf/a1c860e76627365efdb44d6540ffeb36 to your computer and use it in GitHub Desktop.
Jenkins script in Groovy to parse a Github web hook payload for the commit that triggered the pull request that triggered the service hook ... and then set that as a build variable that can be used in further Jenkins scripts or parameterised jobs. See http://chloky.com/github-pull-req-webhook/ and https://gist.github.com/bjhess/2726012 for setti…
import hudson.model.*
def payloadString = build.buildVariableResolver.resolve("payload")
payloadObject = new groovy.json.JsonSlurper().parseText(payloadString)
targetCommit = payloadObject.pull_request.head.sha
build.addAction(new ParametersAction(new StringParameterValue('targetCommit', targetCommit)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment