Trigerring Multibranch Pipelines
(this post if part of the material I cover in my devops course)
In the
previous post (multibranch basics) we have described the basics of creating and using a multibranch pipeline (well, building was manual for each branch, which is not too practical).
In this post, we will learn how to trigger builds for branches using github webhooks.
GitHub hook trigger for GITScm polling
- This is a feature of the
Jenkins Github Plugin.
( read about it in the documentation) - When a github hook message arrives at Jenkins (this is a HTTP POST message), the github plugins checks that it knows what was the repository and branch it was sent from
- Github then uses the git plugin to use SCM polling (once) the repository for changes. If changes are found - new build is triggered.
Configuring Github hook trigger
In a
previous post, we have configured this manually, clicking a checkbox to enable receiving of the github webhook.
In this case, if we go into a specific branch, we'll see that we can view the configuration, not edit it.
So, the idea is tha we'll use pipeline code to manage webhooks.
So, edit your jenkins file, and add this code, right after you tope agent declaration:
1triggers{
2 githubPush()
3 }
(commit and push..) We'll now instruct the github plugin to manage those webhooks inside Jenkins for us.
Configure github plugin to manage webhooks
Configure github:
- Go to: Dashboard->Manage Jenkins->System
- Scroll down and find Github
- Leave the name empty, use the default github url
- Select the myrep-PAM credentials you have created in the previous post
- Check the Manage hooks checkbos, and click Save