Is it possible not to trigger automatic build from Git if only Jenkinsfile is being modified?

Hi,

we are using Multibranch Pipeline and we are using default configuration in jenkins so that once we have some change pushed to the “master” branch our build is being automatically triggered. That works fine.

However, I was wondering if it is possible to somehow “disable” this behavior in cases when we do modification only of the Jenkinsfile and push that change to the master branch as well? Only for that particular case we do not see point at all to have our build job to be triggered because development code for our product is not changed.
Can you tell me if this is supported in any way?

Thank you very much!

SCM Skip maybe? Where you can have a commit message skip the build.

I think you should treat your entire pipeline as development code. So you know if a change breaks ci for any reason early.

Hi Gavin,
thanks for your kind assistance.
I agree with you but this is how this was decided so I cannot influence on that.

If I may check with you:

  1. We need that plugin to be installed
  2. before all my stages I just add this stage
        stages {
            stage('Checkout') {
                steps {
                    scmSkip(deleteBuild: true, skipPattern:'.*\\[ci skip\\].*')
                }
            }

and this will skip the rest of the build. I need to send of course commit message containing [ci skip].
Although I do not have explicitly at all currently checkout stage or actions to checkout in my Jenkins code, only this addition is enough before all my other build stages?

Thank you

that is what it says, but it also says it will then delete that build, which seems really bad to me (effective, but bad).

maybe someone else knows. I think there’s a configuration in how you setup the scm in your pipeline definition that can prevent it from building.

You could use a “when” clause condition that would exclude the Jenkinsfile from the “changeset” detected by Jenkins:

stages {
    stage('Checkout') {
        when {
            not { changeset pattern: "Jenkinsfile" }
        }
        steps {
            // Your steps ...
        }
    }
}

As per Pipeline Syntax.

Would it help in your case?

You can even ensure that it only checks on the branch named main:

stages {
    stage('Checkout') {
        when {
            allOf {
                not { changeset pattern: "Jenkinsfile" }
                branch 'main'
            }    
        }
        steps {
            // Your steps ...
        }
    }
}