4

The multi branch pipeline plugin, awesome as it is, doesn't build tags out of the box. The usage of the basic-branch-build-strategies-plugin is required to enable tag discovery and building.

My question is directly related to: Is there a way to automatically build tags using the Multibranch Pipeline Jenkins plugin?

This plugin works great in the UI but doesn't appear to be easily configurable using the Jenkins job dsl. Does anyone have any examples of how to set the branch strategies using the dsl (or dsl configure->) so that tags will be discovered and built?

Having examined the delta between the config.xml files when the settings are changed via ui, it looks like I need to be able to add this trait:

<org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait />

and this section under build strategies:

<buildStrategies
    <jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl
        plugin="basic-branch-build-strategies@1.1.1">
        <atLeastMillis>-1</atLeastMillis>
        <atMostMillis>172800000</atMostMillis>
    </jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl>
</buildStrategies>
Brian Call
  • 41
  • 1
  • 5

1 Answers1

4

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 suggested by the dynamically generated 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'()
  }
Narthana Epa
  • 81
  • 1
  • 4