jenkinsjenkins-pipelinemaven-scm

How to skip SCM trigger on certain message


I am using declarative Jenkinsfile for a multi-branch pipeline as shown here. SCM is set to poll for every 5 minutes.

pipeline {
    agent none
    stages {
        stage('Build Jar') {
            agent {
                docker {
                    image 'maven:3.6.0-jdk-11'
                    args '-v $HOME/.m2:/root/.m2'
                }
            }
            steps {
                sh 'mvn clean package release:clean release:prepare release:perform -Darguments="-Dmaven.deploy.skip=true" -DscmCommentPrefix="[skip ci]"'
            }
        }
        stage('Build Image') {
            steps {
                script {
                    app = docker.build("myname/myimage")
                }
            }
        }


        //other stages here


}

Problem:

maven release commits changes to the repo which triggers another build. So it gets triggered indefintely. I came across this SCM Skip plugin.

scmSkip(deleteBuild: true, skipPattern:'.*\\[skip ci\\].*')

But unfortunately it needs an agent to run!!


I also tried by using agent any. no luck.

  pipeline {
        agent any
        stages {
          stage('SCM Check') {
            steps {
                 scmSkip(deleteBuild: true, skipPattern:'.*\\[skip ci\\].*')
            }
          }
            stage('Build Jar') {
                steps {
                    sh 'mvn clean package release:clean release:prepare release:perform -Darguments="-Dmaven.deploy.skip=true" -DscmCommentPrefix="[skip ci]"'
                }
            }
            stage('Build Image') {
                steps {
                    script {
                        app = docker.build("myname/myimage")
                    }
                }
            }


            //other stages here


    }

How do you guys skip build on certain messages?


Solution

  • I had to go with the below plugin which excludes the certain commiter. It works great.

    https://github.com/jenkinsci/ignore-committer-strategy-plugin