I have configured a Github web hook with the below settings: Payload URL: https:///github-webhook/ Content Type: application/x-www-form-urlencoded Events : Pushes, Pull Requests
The Jenkins job that I have, is a pipeline job that has the below enabled: Build Trigger: GitHub hook trigger for GITScm polling
With the above configuration, I see that in response to an event ie; push/PR in GitHub, the jenkins job gets triggered successfully. In GitHub, under Recent Deliveries for the web hook, I see the details of the payload and a successful Response of 200.
I am trying to get the payload in Jenkins Pipeline for further processing. I need some details eg: PR URL/PR number, refs type, branch name etc for conditional processing in the Jenkins Pipeline.
I tried accessing the "payload" variable (as mentioned in other stack overflow posts and the documentations available around) and printing it as part of the pipeline, but I have had no luck yet.
So my question is, How can I get the payload from GitHub web hook trigger in my Jenkins Pipeline ?
Unsure if this is possible.
With the GitHub plugin we use (Pipeline Github), PR number is stored in the variable
CHANGE_ID. PR URL is pretty easy to generate given the PR number. Branch name is stored in the variableBRANCH_NAME. In case of pull requests, the global variablepullRequestis populated with lots of data.Missing information can be obtained from Github by using their API. Here's an example of checking if PR is "behind", you can modify that to your specific requirements: