One of the most basic requirement of CI implementation using Jenkins is to automatically trigger a Jenkins job post every commit. As you are already aware there are two ways in which a Jenkins job can be triggered in an automated fashion is:
- Pull | PollSCM
- Push | Webhook
It is a no-brainer that a Push-based trigger is the most efficient way of triggering a Jenkins job else you would be unnecessarily hogging your resources. One of the hurdles in implementing a push-based trigger is that your VCS & Jenkins server should be in the same network or in simple terms they can talk to each other.
In a typical CI setup, there is a SAAS VCS i.e GitHub/GitLab and a privately hosted Jenkins server, which make a Push-based triggering of Jenkins job impossible. Till a few days back I was under the same impression until I found this awesome blog that talks about how you can integrate a Webhook with your private Jenkins server.
In this blog, I’ll be trying to explain how I implemented the Webhook relay. Most importantly the reference blog was about integration of WebhookRelay with GitHub, with GitLab still there were some unexplored areas and I faced some challenges while doing the integration. This motivated me to write a blog so that people will have a ready reference on how to integrate GitLab with Webhook Relay.
Step 1: Download WebHook Relay Agent on the local system
curl -sSL https://storage.googleapis.com/webhookrelay/downloads/relay-linux-amd64 > relay && chmod +wx relay && sudo mv relay /usr/local/bin
Note: Webhook Relay and Webhook Relay agent are different. Webhook Relay is running on public IP which triggers by GitLab and Webhook Relay Agent is a service which gets trigger by Webhook relay.
Step 2: Create a Webhook Relay Account
Step 3: Setting up the Webhook Relay Agent.
relay login -k token-key -s token-secret
Step 4: Create GItLab Repository
We will keep our repository a public one to keep things simple and understandable. Let’s say our Gitlab repository’s name is WebhookProject.
Step 5: Install GitLab and GitLab Hook Plugin.
Step 6: Create Jenkins Job
Step 7: Connecting GitLab Repository, Webhook Relay, and Webhook Relay Agent
The final and most important step is to Connect the Overall flow.
Start forwarding Webhooks to Jenkins
Open terminal and type command:
relay forward --bucket gitlab-jenkins http://localhost:8080/project/webhook-gitlab-test
The most critical part of the workflow is the link generated by the Webhook Relay Agent. Copy this link and paste Gitlab repository(webhookProject) → Settings → Integrations
Gitlab Repository → Settings → Integrations → webhook → Edit
Webhook Relay UI page → Relay Logs.
So now you know how to do WebHook integration between your VCS & Jenkins even when they are not directly reachable to each other.
Can you integrate a GitHub Webhook with Privately hosted Jenkins? Yes
Cheers Till Next Time!!!!
5 thoughts on “Can you integrate a GitHub Webhook with Privately hosted Jenkins No? Think again”
Nice blog and very helpful.
Brief and precise Nice work
new concept, very helpful
Meh, in free version only 150 actions / month. Far from enought even for single developer…