Quick Tip: Using [skip-ci] in Jenkins’ Declarative Pipelines

You’ve spent the past hour meticulously crafting a Readme update and its time to commit. Great, but what if you don’t want that commit to trigger automated testing, deploys, and other actions? If you’re using Jenkins declarative pipelines there’s a pretty simple solution.

Add the below when block to each stage you wish to skip in your Jenkinsfile.

when {
    not {
        changelog '\\[skip-ci\\]'
    }
}

We can also expand upon this for other actions if desired. For example, use the following around a deploy stage to avoid deploying pull requests, anything not on the master branch, and to respect the [skip-ci] param in a commit message.

stage('Deploy'){
    when {
        allOf {
            branch 'master'
            not {
                anyOf {
                    changeRequest author: '', authorDisplayName: '', authorEmail: '', branch: '', fork: '', id: '', target: '', title: '', url: ''
                changelog '\\[skip-ci\\]'
            }
          } 
       }
}
steps {
    deploy()
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s