我试图在Jenkins中设置当前的构建状态,并看到这种奇怪的行为:
Jenkinsfile
node('master') {
checkout(scm)
lib = load("Jenkinsfiles/Jenkinsfile_functions.groovy")
docker_lib = load("Jenkinsfiles/lib/docker.groovy")
lib.cancel_existing_pull_request_builds()
stage('StartPipeline') {
lib.notifyStash('INPROGRESS')
lib.notifyBuild('STARTED')
}
...
还有
lib.notifyStash('INPROGRESS')
def notifyStash(String state, displayName=null) {
def states = ['SUCCESS', 'FAILED', 'INPROGRESS']
if(states.contains(state)) {
currentBuild.result = state
println("#1 Current State of Build is: " + currentBuild.result)
} else {
throw new AbortException("NotifyStash State: " + state + " needs to be in " + states)
}
originalName = currentBuild.displayName
currentBuild.displayName = originalName
println("#2 Current State of Build is: " + currentBuild.result)
}
我看到以下结果:
[Pipeline] { (Jenkinsfiles/lib/docker.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] stage
[Pipeline] { (StartPipeline)
[Pipeline] echo
#1 Current State of Build is: FAILURE
[Pipeline] echo
#2 Current State of Build is: FAILURE
为什么将状态设置为“失败”?我专门将其设置为INPROGRESS。