Thatâs right, as promised, Iâm going to torture myself with Jenkins some more, this time with multi-branch pipelines!
If you missed it, I recently wrote a blog post in which I explained how to integrate Jenkins and Github with freestyle jobs. In that post, I stipulated that were I able to use Multi-Branch pipelines, my life would have been much easier. Well, itâs true. Sort of. Multi-branch pipelines, once you get them working are much, much better than freestyle jobs. As you may have guessed, the problem is the initial setup, because Jenkins has incredibly cryptic error messages. Thanks pals.
Anyway, Iâve figured it out so you donât have to, so letâs get started!
The first thing you want to do is set up your github user account and repository, before you even touch Jenkins. Unlike last time, where the order of things didnât matter , this time itâs extremely important if you want everything to go smoothly.
Navigate to your personal access tokens settings on Github. You want to create a token with the following permissions:admin:org_hook, admin:repo_hook, repo, user:email
Theyâre a bit more powerful than last time, but that does mean that Jenkins can set up the repo hooks for you so you donât have to.
Now go to your repository and create a Jenkinsfile. Thatâs right, weâre creating the CI/CD pipeline before weâve even touched Jenkins at all. This is because if Jenkins doesnât find a Jenkinsfile, it pretends that your credentials are wrong and sends you on a wild goose chase, even if theyâre absolutely fine. So just pick one of the hello world examples â it really doesnât matter what, and all they do is display a version string, but you really want a valid Jenkinsfile.
Now go to Jenkins and click create new job or new item, and select multi-branch pipeline. Coincidentally, if this is the first time youâve ran Jenkins, you might get an infinite loading screen. If that happens, just turn it off and back on again.

- Click the âadd sourceâ dropdown and select Github.
- Within credentials, click âaddâ and select âJenkinsâ.
- Keep Kind as âusername with password.
- As username, enter your github username
- As password, enter the access token from earlier. If youâve lost it, like I have, you can just regenerate it provided itâs not being used anywhere else.
- Under repository https url enter the url of your repository, which can be a private repo.
Now if you click apply and save, your github repo should have a new webhook!
If itâs worked so far, you may be tempted to click on âScan repository nowâ. Bad idea. It wonât work, and it will confuse you.
What you ACTUALLY have to do, is commit a change to master (or whatever branch has the Jenkinsfile). If you do that, and wait a minute, it should automatically build!
The commit on Github will also be updated to show success or failure.
Youâll also see PR status!
As you can see, Multi-branch pipelines are already much easier to work with! I just wish Jenkins werenât so cryptic â I wasted way too much time thinking it wasnât working because I either hadnât given it enough permissions, or I thought scanning was supposed to work.
Hope you have found this informative! Maybe next time Iâll dive deeper into multi-branch pipelines and build something cool!




Top comments (0)