Skip to content

Webhooks

Ramon Goncalves da Silva edited this page May 5, 2017 · 4 revisions

Setting up pull requests

First install Github pull request builder plugin and it's depedencies in Jenkins using the plugin manager. The plugin's github page provides a step-by-step guide on how to add the Github integration to the project.

Changing the pull request status

Setting the build status can be set by using the following script as a task in job configuration after building the project:

if [[ $BUILD_STATUS == "success" ]]
then
  export STATUS="success"
else
  export STATUS="failure"
fi

curl "https://api.github.com/repos/username/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \
  -H "Content-Type: application/json" \
  -X POST \
  -d "{\"state\": \"$STATUS\", \"description\": \"Jenkins\", \"target_url\": \"http://my.jenkins.box.com/job/dividata/$BUILD_NUMBER/console\"}"

Script source

Where you need to replace the url with url of your repository and replace the Personal access token. It’s recommended to create a separate Github user for Jenkins, which will need push rights for the repository.

Setting up a server

For the Github pull request plugin to work, a webhook is needed. Because our Jenkins was running on localhost, we set up ngrok to test the pull request. Ngrok is a forwarding service, which can be used to bind local addresses to a public address. Ngrok can be run with the following command in terminal.

./ngrok http 8080

Ngrok will give a forwarding address, which then can be used for the webhook in the Jenkins. It can be set in Manage JenkinsGitHub Pull Request BuilderJenkins URL override.

Configuration

The Pipeline

Radiators

Clone this wiki locally