简体   繁体   中英

Making changes in configuration of a jenkins job using Job DSL plugin

I am dynamically creating new job in jenkins when a new branch is created in BitBucket. These jobs are copy of an existing "template_job". Now I want to update the configuration of "Branches to Build" and my workspace. Below is the code to create a new job using the template job.

job(branch_name) {
    using('template_job')
}

I am using the below code to update my branch to build.

job(branch_name) {
    using('template_job')
    scm {
        git {
            branch(branch_name)
        }
    }
}

But this is erasing all the contents in configuration. Kindly help me resolve this issue.

SCM configuration can not be updated partially.

But you can use a Configure Block to update the relevant parts of the config XML:

job('example') {
  using('template_job')
  configure { node ->
    node / scm / branches / 'hudson.plugins.git.BranchSpec' / name('bar')
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM