Job-DSL Plugin introduction:

https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin

Configuration

After installing the plugin, you'll get a new Build Step entry named "Process Job DSLs". Type the DSL directly in the text box, or point to a file in the workspace.

Basics

The DSL allows the definition of a job, and then offers a useful set of functions to configure common Jenkins items. A configure is available to give direct access to the config.xml before generating the job. The script is groovy code, which can be very powerful.

Example

Process: (config + templates) + py --> generate groovy DSL Files --> Jenkins read the groovy DSL files to generate Jobs

1. Config files: (json or yaml format): It is used to pass the specified arguments for the tempate file and generate different job groovy files.

 

2. template file: A base file of the job template

#compiler-settings
cheetahVarStartToken = &
#end compiler-settings

job('&JOB_NAME') {
  description '&JOB_DESCRIPTION'
  label 'HOST_LABLE'
  steps {
    batchFile('''do whatever you want''')
  }
  publishers {
    downstreamParameterized {
      trigger('&DOWNSTREAM_JOB') {
        condition('SUCCESS')
        parameters {
          predefinedProps(['ORI_EXPORT_DIR': '$ORI_EXPORT_DIR'])
        }
      }
    }
  }
  #include 'sub_tmpl/email.tmpl'
}

 Note: 1) cheetahVarStartToken = & means the variables starts with & in this template

          2) downstreamParameterized means you need to install the Parameterized Trigger plugin

          3) Use '#include 'sub_tmpl/email.tmpl' to include another template file

3. Write a python script file to generate the DSL groovy files.

 

(For the details, please refer to "有道笔记")

 

posted on 2016-07-13 15:34  漂浮的心  阅读(244)  评论(0)    收藏  举报