Jenkins Job Builder Github action
When codifying Jenkins jobs, you have two options:
- Job DSL + seed job. More native to Jenkins, but requires Groovy scripting.
- Jenkins Job Builder. A third party solution, but configs are in yaml, so it’s easier to get started.
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:
- Create Jenkins API token.
- Use it to create
JENKINS_TOKEN
secret in repo settings. - 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