Can Jenkins work be interrupted with success?

In a declarative pipeline, using a multivariate job and a Jenkins file, can work be interrupted with an exit code successrather than an exit code failure?

In the next step, I basically check if the commit that started the job contains "ci skip", and if so, I want to interrupt the work.

Use errorinterrupts the task, but also marks it as such (red line). I would like this work to be marked with a green line.

stage ("Checkout SCM") {
   steps {
      script {
         checkout scm
         result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true) 
         if (result == 0) {
            error ("'ci skip' spotted in git commit. Aborting.")
         }
      }
   }
}

Edit:

Instead of the above, I'm now trying to simply skip all the steps if git commit contains "ci skip". I understand that if the result is expressionequal false, it should skip the stage ...

pipeline {
    environment {
        shouldBuild = "true"
    }
    ...
    ...
    stage ("Checkout SCM") {
        steps {
            script {
                checkout scm
                result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true) 
                if (result == 0) {
                    echo ("'ci skip' spotted in git commit. Aborting.")
                    shouldBuild = "false"
                }
            }
        }
    }

    stage ("Unit tests") {
        when {
            expression {
                return shouldBuild
            }
        }
        steps {
            ...
        }
    }
    ...
    ...
}
+6
2

, environment, parameters.

, parameters pipeline:

parameters {
      booleanParam(defaultValue: true, description: 'Execute pipeline?', name: 'shouldBuild')
   }

git, "ci skip", shouldBuild:

env.shouldBuild = "false"

expression:

expression {
    return env.shouldBuild != "false" 
}

. , git "ci skip", , SUCCESS.

+4

, SUCCESS, .

ci-skip shared library, NOT_BUILT. , , when .

, :

pipeline {
  stages {
    stage('prepare') { steps { ciSkip action: 'check' } }
    // other stages here ...
  }
  post { always { ciSkip action: 'postProcess' } }
}

. .

+1

Source: https://habr.com/ru/post/1016034/


All Articles