Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Making Jenkins Behave 2: Electric Boogaloo
Erry Kostala
Erry Kostala

Posted on

     

Making Jenkins Behave 2: Electric Boogaloo

Jenkins Being All Formal

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 explainedhow 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 yourpersonal 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 thehello 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 clickcreate new job ornew item, and selectmulti-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.

have you tried turning it off and on again
“Hello, IT, have you tried turning it off and 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!

Jenkins showing the branches

The commit on Github will also be updated to show success or failure.

Github commit updates
Github commit updates

You’ll also see PR status!

PR status is shown
PR status is shown

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I fight software and sometimes don't lose.
  • Location
    London
  • Joined

More fromErry Kostala

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp