Jenkins + Pipeline + Job Builder = fast growing ❤

Alexey Alter-Pesotskiy
testableapple
Published in
3 min readMay 27, 2019

This Note originally published on my Personal Blog here. Read original note so that you won’t miss any content.

The story about Jenkins which is deploying himself

Jenkins — free, flexible, popular and gorgeous continuous integration server.

Jenkins Pipeline — plugin to build continuous delivery pipelines as a code.

Jenkins Job Builder — tool to make jobs from templates in a human readable text format and keep them in a version control system (further JJB).

Purpose

  • minimize an interaction with Jenkins UI
  • provide CI which will deploying itself
  • make it easy and flexible

Precondition

Provide access for JJB

  • go to user configuration page:
http://<jenkins url>/user/<user name>/configure
  • generate API Token:
  • create jenkins_jobs.ini file in the root of repository and put API Token (password field) and User Name (user field) there:
[jenkins]
password=2433a61e9bc33fb4633de6d39d332b33
user=a.alterpesotskiy

CI Server which is deploying itself

Our first job will be the most important. It will be essential, because of its influence. This job will have to update all Jenkins jobs after every commit with changes. We will call it “JenkinsDeploy”. So, let’s go:

  • create JenkinsDeploy job via Jenkins web interface

This is an exception, because it will be only the one job we create via Jenkins UI

  • create JenkinsDeploy.yml template in the jobs/ folder
  • fill the template like this:

I’ll try to explain what is taking place in the job template:

  • Jenkins clone the repository with a project from git (via scm plugin)
  • JJB is updating Jenkins jobs from templates (via jenkins-jobs cli)
  • It does it after each commit (checking for changes every minute)

Project contents

Sample: JJB + Pipeline

Finally I might to show how everything works here at the simple example. How to make it as simple as possible? We will build a job, that will create an empty folder. That’s all.

  • template (jobs/mkdir.yml)
  • pipeline (pipeline/mkdir.groovy)

So, this job will be automatically deployed after push via JenkinsDeploy job.

Conclusion

What opportunities does it open?

  • We might to describe whole CI/CD process as a code.
  • We might to combine many jobs and pipeline scripts in one template via JJB.
  • We might to relish of the resulting workspace.
  • We might to spend our obtained free time on useful things.

Also I would like to add that via JJB we can describe many Jenkins Plugins in .yml/.json representations and use many strategies to make our pipelines more flexible and expandable. If it was at least a little bit interesting, you can borrow much more interestingness from the official documentation:

https://buildmedia.readthedocs.org/media/pdf/jenkins-job-builder/latest/jenkins-job-builder.pdf

Thanks for reading! Thanks for claps (:

--

--