When codifying Jenkins jobs, you have two options:

If you prefer DSL, can stop reading now. JJB users - read on.

Since we’re automating all, it’d be great to have the configuration applied on a repo push. Of course, it’s possible to configure a seed job for JJB as well, but point and click is annoying. How about a github action instead?

Configuration is very simple:

  1. Create Jenkins API token.
  2. Use it to create JENKINS_TOKEN secret in repo settings.
  3. Add workflow yaml, something like this:
name: jjb

on:
  push:
    paths:
      - jenkins/jobs/** # job definitions here, searched recursively

jobs:
  jjb:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: devopsx/gha-jjb@master
        with:
          jenkins_token: ${{ secrets.JENKINS_TOKEN }}
          jjb_dir: jenkins/jobs # same dir with definitions as in push stanza
          jjb_ini: jenkins/jenkins_jobs.ini

That’s it! Now your builds will be automatically updated each time you push.

Comments