Tuesday, December 13, 2016

Programming Jenkins jobs with Job DSL

The Jenkins job configuration can be programmed using Job DSL, instead of manually configuring it for the following advantages

  • Job configuration can be version controlled under tools like GIT.
  • Easily apply modifications to numerous existing jobs, by changing code and re-running DSL
  • It provides the centralised location to view and analyse all Jenkins job config information
What you need to start with Job DSL?
  • Job DSL Plugin
  • Little bit of Groovy language knowledge

Job DSL Plugin

Install Job DSL plugin and then you'll get a new build step, 'Process Job DSLs' under 'Freestyle project'

Usage

You can run DSL code either

1) By providing DSL groovy code directly at 'DSL Script' section. This option is useful while testing your DSL code. In the below screen shot contains DSL instruction for the job named 'build-hyperloop'

 

2) or Store your DSL code in a groovy file (for ex. myjob.groovy) and ensure it is available in the job workspace. Select 'Look on Filesystem' option and provide the location of this groovy code at 'DSL Scripts'

 

Now save and 'Build' this job and it will create a new Jenkins job by name 'build-hyperloop' if not exist or if this job already exists, then it updates the job with this configuration

End to End flow

No comments: