- Use Case
- Log in →
- Server Sent Events (SSE) - WS alternative, Go and Vue.js example
- Rewrite webhook body
- Docker Compose update on Github webhook
- Using Google Firestore for a Golang backend application
- Automated Jenkins builds on GitHub pull request
- Rules-based webhook filtering & routing
- Introducing Cloudflare support for Home Assistant remote access
- Setting up simple, self-hosted & fast CI/CD solution with Drone.io
- Controlling TV with Google Home, IFTTT and Node-RED
- Node-RED OwnTracks location tracking without public IP/MQTT
Automated Jenkins builds on GitHub pull request
Apr 17, 2019, by Karolis Rusenas
In this short guide we will configure Jenkins to start builds on GitHub pull requests. Subsequent builds will be triggered on any new commits and GitHub pull request status will show whether build succeeded or failed. This setup will work without configuring router, firewall or having a public IP. It will also work behind a corporate firewall.
In my case, I just grabbed a Vagrant box from https://app.vagrantup.com/ubuntu/boxes/xenial64:
And we have our VM. You can get the IP address by typing
ifconfig in the terminal.
I mostly followed this guide https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/. The only caveat I encountered this time with Jenkins, was the jdk version mismatch.
First, get your Jenkins token:
Then, either open your node firewall (or check Vagrant port forwarding) or do the easy thing: connect with the relay:
To get the CLI, check instructions here. On a 64-bit Linux OS it’s:
Go to https://my.webhookrelay.com/tokens, click CREATE TOKEN and copy/paste login command into the terminal, it should be something like:
Now, open the browser. You should see a similar screen:
Follow the steps to configure your Jenkins initial admin user.
Plugin installation instructions can be found here.
Once you have it, add GitHub credentials - your username and GitHub token.
Once you have the
relay CLI on the machine where you run Jenkins, type:
This will start forwarding webhooks. There are alternative options to run the forwarding daemon, such as Docker container.
If you are creating webhook configuration manually in GitHub, use http://localhost:8080/ghprbhook destination as it’s the endpoint on which the plugin is listening for webhooks. In default case, Jenkins will automatically transform https://my.webhookrelay.com/v1/webhooks/21e13033-bd3d-47a2-bf15-6fd42d4b40a3 endpoints to https://my.webhookrelay.com/v1/webhooks/21e13033-bd3d-47a2-bf15-6fd42d4b40a3/ghprbhook and
Webhook Relay will preserve the extra
Now, configure GitHub Pull Request Builder:
To create a new job, first select “Freestyle project”, then:
Add the project’s GitHub URL to the “GitHub project” field (the one you can enter into browser. eg: “https://github.com/rusenask/jenkins-test/“):
Configure Source Code Management section:
- Select Git SCM.
- Add your GitHub “Repository URL”.
- Under Advanced, set “refspec” to
- In “Branch Specifier”, enter
Configure Build Triggers with a list of admins and tick the
use github hooks for build triggering:
Add your Build step configuration. This can be anything you want, usually people tend to use either a bash script, Makefile target or something specific to your programming language such as
Now, whenever you open a new pull request in GitHub, you should see a build being triggered:
You can view build status in your Jenkins instance as well. This build indicator in GitHub will either turn red or green based on the build status.
As we can see, there are several required steps to make sure your PRs get automatically built and tested when using Jenkins. Those can be split into two groups:
- System configuration that involves:
- setting Webhook Relay agent to forwarding webhooks
- installing and configuring GitHub pull request builder plugin
- Whenever you create a new project in Jenkins, setting up few settings. The first time I did this it took me some time to go through the configuration options, but second and third time didn’t take more than 1 minute :)
I hope you will find this guide useful!
P.S. Bonus troubleshooting below:
When we are talking about Jenkins, there are many ways for things to go wrong. Multiple plugin versions, corporate proxies and different operating systems contribute to all of this. I have compiled a short list of items for you to check if you encounter problems.
Make sure there’s an automatically created GitHub repository webhook configuration:
Normally, connected agent should look like this:
If you are behind a corporate proxy, try adding
--ws flag to change default transport type from GRPC to WebSocket:
There will be several sources of logs you can check out:
- Jenkins logs under
- Webhook Relay forwarding logs:
- CLI logs: