SEANK.H.LIAO

jenkins github push

running jenkins jobs on github push

jenkins job dsl

I was browsing through our central jenkins jobs repo at work (which uses the Job DSL plugin) and noticed that all the git jobs were triggered by:

1job('something--build-master') {
2  triggers {
3    scm('H/5 * * * *')
4  }
5}

Which i thought was... not very efficient. Thankfully the fix was relatively easy since we're using github:

1job('something--build-master') {
2  triggers {
3    githubPush()
4  }
5}

as well as registering a webhook for push events in github for: (note this is different from the webhook for pull requests you may also be using)

1https://jenkins.example.com/github-webhook/

freestyle jobs

Job DSL is all nice and good, but we also have a "Seed Job", which pulls in our git repo of Job DSL jobs. I also wanted this to trigger on push:

1import com.cloudbees.jenkins.* // has the definition for GitHubPushTrigger
2
3def job = new FreeStyleProject(Jenkins.getinstance(), "Seed-Job");
4job.addTrigger(new GitHubPushTrigger());

note on job definitions

There are... many ways to write jenkins jobs, but if you think something doesn't make sense, just remember that everything compiles down to an XML document describing the job. Looking at these output XML files, it should be easy to reverse engineer what you need to write in whatever job syntax you happen to be stuck with.