Disabling a Multibranch Pipeline using Job DSL

Featured image for sharing metadata for article

Using Job DSL to manage your pipelines is useful, but sometimes you want to not run a pipeline, for instance so it doesn't trigger in your test environment.

Post Jenkins 2.263

It appears that between Jenkins 2.235.5 (when I last checked this) and Jenkins 2.263, this is now possible to do via a configure block:

factory.multibranchPipelineJob(jobLocation) {
  configure {
    it / disabled << 'true'
 }
}

Pre Jenkins 2.263

In the Jenkins UI, you can click a Disable button which disables the project, but interestingly this doesn't change the job's XML behind the scenes, so it seems to be controlled through some other Jenkins state.

This means we need to think a bit out of the box to do this, which led me to the use of the excludes property, where we can exclude all the branches that are discovered:

factory.multibranchPipelineJob(jobLocation) {
  branchSources {
    /* for example */
    git {
      // other config
      excludes('*')
    }

    /* for example, when using GitHub */
    github {
      // other config
      excludes('*')
    }

I'd also recommend, in the cases we disable the pipeline, we update the description of the job to make it clear it's disabled.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #jenkins #job-dsl.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.