jenkins管道岗位条件一直进入变化的条件,除非SUCCESS

时间:2018-01-26 19:45:02

标签: jenkins conditional jenkins-pipeline

运行Jenkins ver。 2.89.2

采用声明性管道。

pipeline {
  agent none
  stages {
    stage('init') {
      steps {
        script {
          currentBuild.result = 'SUCCESS'
          //currentBuild.result = 'UNSTABLE'
          //currentBuild.result = 'FAILURE'
          //currentBuild.result = 'ABORTED'
        }
      }
    }
  }
  post {
    always {
      echo "Always: $currentBuild.currentResult vs $currentBuild.result"
    }
    changed {
      echo "Changed: $currentBuild.currentResult vs $currentBuild.result"
    }
    success {
      echo "Success: $currentBuild.currentResult vs $currentBuild.result"
    }
    unstable {
      echo "Unstable: $currentBuild.currentResult vs $currentBuild.result"
    }
    failure {
      echo "Failure: $currentBuild.currentResult vs $currentBuild.result"
    }
    aborted {
      echo "Aborted: $currentBuild.currentResult vs $currentBuild.result"
    }
  }
}

多次运行SUCCESS会产生一个输出(在后续运行时不会进入更改块):

[Pipeline] echo
Always: SUCCESS vs SUCCESS
[Pipeline] echo
Success: SUCCESS vs SUCCESS

但是,在运行任何其他状态(不稳定,故障等)时始终输入change

[Pipeline] echo
Always: UNSTABLE vs UNSTABLE
[Pipeline] echo
Changed: UNSTABLE vs UNSTABLE
[Pipeline] echo
Unstable: UNSTABLE vs UNSTABLE

我希望第一次"改变"进入更改块的状态,但不是后续的状态。这适用于SUCCESS结果。为什么不通过其他结果?

1 个答案:

答案 0 :(得分:0)

正如@mkobit正确回答的那样,JENKINS-48752涵盖了这一点。再次感谢。