Rod Kimble
Rod Kimble

Reputation: 1364

exit pipeline job withou failing

In my Jenkins instance I use shared libraries. In my first step I perform a integrity checkout. On the beginning of this checkout I check if there are changes regarding my reopsitory. If there are no changes I want to exit the whole pipeline job WITHOUT changing the build status to unstable.

mainpipeline:

step('checkout'){
     performIntegrityCheckout()
}

performIntegrityCheckout:

 //PERFORM INTEGRITY CHECKOUT
 if(changes == "false"){
      //EXIT HERE
 }

I tried to use return but this only ends the current closure. Any ideas?

Upvotes: 0

Views: 143

Answers (1)

Aaron Rosenberg
Aaron Rosenberg

Reputation: 161

You could try setting an environment variable and then using it to skip each stage...

pipeline {
  agent any
  stages {
    stage('Stage 1') {
      when {
        environment name: 'CHANGES_EXIST', value: 'true'
      }
      steps {
        echo "I am running stage 1"
      }
    }
    stage('Stage 2') {
      when {
        environment name: 'CHANGES_EXIST', value: 'true'
      }
      steps {
        echo "I am running stage 2"
      }
    }
  }
  environment {
    CHANGES_EXIST = getChangesExist()
  }
}

def getChangesExist() {  
  if (<your integrity check goes here>) {
    return "true"
  } else {
    return "false"
  }
}

Upvotes: 1

Related Questions