Disabling a Multibranch Pipeline using Job DSL

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.

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

    /* for example, when using GitHub */
    github {
      // other config

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.

Related Posts

Other posts you may be interested in:

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.