Jenkins Job DSL for beginners

This post helps you to create a basic Jenkins job-dsl groovy file for a previously created readymade free-style Jenkins job. Follow previous post to set up a main DSL job to automate all the Jenkins jobs:

  • Create a Jenkins Job-DSL groovy file, your_jenkins_job_name.groovy 
freeStyleJob('your_jenkins_job_name') {
    description 'your project description'
    logRotator(numToKeep = 100)
    scm {
       git {
        remote {
            # provide the credentials to let you clone git repo

# insert multiple shell files to execute sequentially
steps {

# enable Jenkins Global passswords
wrappers {
    injectPasswords{ injectGlobalPasswords() }

# publish a conslidated html report in the Jenkins dashboard
publishers {
   publishHtml {
    report('your_project/reports/') {
        reportName('Report Title')
        reportFiles('your_report_1.html, your_report_2.html, your_report_3.html')
  • The above Groovy script can also be generated by readymade through a Jenkins plugin, XML Job to Job DSL 
  • Go to Manage Jenkins -> Manage Plugins -> Available
  • Search for XML Job to Job DSL Plugin, install and restart Jenkins after download

  • Now, you will be finding an option to convert any of your Jenkins job to DSL
  • Click on the XML Job to DSL link, select the job to be converted, and click on the Convert selected to DSL button

  • Finally, download the DSL file

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s