How to configure basic branch build strategies plugin using job dsl? How to configure basic branch build strategies plugin using job dsl? jenkins jenkins

How to configure basic branch build strategies plugin using job dsl?


Something like

multibranchPipelineJob('pipline') {  ...  branchSources {    branchSource {      source {        github {          ...          traits {            ...            gitTagDiscovery()          }        }        buildStrategies {          buildTags {            atLeastDays '-1'            atMostDays '20'          }        }      }    }  }}

is what I've been working with. It's not documented in the plugin, but that doesn't stop the job-dsl plugin from dynamically generating the API calls for it.

You can see what the API for your specific Jenkins installation is by going to {your_jenkins_url}/plugin/job-dsl/api-viewer/index.html.Sometimes things won't appear there because a plugins lacks support for job-dsl.In that case you can still generate the xml with the Configure Block.However, this is pretty clumsy to use.

Edit: At least if I use gitHubTagDiscovery() as suggest by the dynamically generate API, Jenkins will crash. Instead, the configure block has to be used to get all the discovery methods for github.

  configure {    def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits    traits << 'org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait' {      strategyId(1)    }    traits << 'org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait' {      strategyId(1)    }    traits << 'org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait'()  }