Toger Blog

Jenkinsfile and Github Hooks

Jenkins is the juggernaut of the build pipeline ecosystem. Its roots go back to bespoke local build pipelines and dedicated build engineers. In present days the likes of CircleCI, CodeShip, Drone.io have started nipping at Jenkins heels.

One of the significant differences is that, historically, Jenkins builds are configured inside Jenkins. The contemporary alternatives generally favor a SCM-managed configuration file (often YAML format). This is useful as it removes the specialness of the Golden Build Host (ever had someone corrupt a Jenkins configuration? Getting back to par is a pain).

Jenkins has joined the in-repo build configuration with their Jenkinsfile. Unfortunately the documentation for this format is abysmal. Truly wretched. The other day I was trying to make use of the Multibranch Workflow aka Pipelines function in Jenkins and attempted to get a Github-triggered build hook working. Hours of googling around to try to find what this should look like and I eventually stumbled across the sample below. Having found it I’ve further looked to see if there was any location in any sort of official documentation such that I should have been able to discern this as the correct answer, and come up empty. I truly do not know how anyone makes all but the most trivial Jenkinsfile’s function.

Having ranted about that, the resulting sample is:

Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
properties([
    pipelineTriggers([
      [$class: "GitHubPushTrigger"]
    ])
  ])


node('docker') {
  checkout scm

  stage('Create Docker Image') {
   sh 'docker build -t dockerhub.example.com/example:latest .'
  }
}