英文:
How to access replayed build's current status in Jenkinsfile
问题
当我重放一个构建时,我想要访问该构建的当前状态。我在这里检查了currentBuild
对象的属性,但找不到任何解决方法。
def replayClassName = 'org.jenkinsci.plugins.workflow.cps.replay.ReplayCause'
def cause = currentBuild.getBuildCauses(replayClassName)
def isReplay = !(cause.isEmpty())
if (isReplay) {
if (REPLAYED_BUILD_STATUS == 'SUCCESS') {
// 做一些操作
} else {
// 做其他操作
}
}
我尝试了currentBuild.result
和currentResult
属性,但它们返回null
。
英文:
When i replay a build, I would like to access that build's current status. I checked currentBuild
object's properties in here but could not find any solution.
def replayClassName = 'org.jenkinsci.plugins.workflow.cps.replay.ReplayCause'
def cause = currentBuild.getBuildCauses(replayClassName)
def isReplay = !(cause.isEmpty())
if(isReplay) {
if(REPLAYED_BUILD_STATUS == 'SUCCESS'){
// Do something
} else {
// Do something else
}
}
I have tryed currentBuild.result
and currentResult
properties but they return null
答案1
得分: 1
IMHO replays not usefull in scripted pipeline
But if you want to get couse build result you must at first get that build:
> and it may be needs approval in jenkins
pipeline :
pipeline {
agent any
stages {
stage('Hello') {
steps {
script{
def replay_couse = currentBuild
.rawBuild
.getCause(org.jenkinsci.plugins.workflow.cps.replay.ReplayCause)
if(replay_couse){
print replay_couse.getOriginalNumber()
print replay_couse.getOriginal().result
}
else{
print 'not replayed'
}
}
}
}
}
}
some refs : getOriginal() Jenkins-examples getCouse
英文:
IMHO replays not usefull in scripted pipeline
But if you want to get couse build result you must at first get that build:
> and it may be needs approval in jenkins
pipeline :
pipeline {
agent any
stages {
stage('Hello') {
steps {
script{
def replay_couse = currentBuild
.rawBuild
.getCause(org.jenkinsci.plugins.workflow.cps.replay.ReplayCause)
if(replay_couse){
print replay_couse.getOriginalNumber()
print replay_couse.getOriginal().result
}
else{
print 'not replayed'
}
}
}
}
}
}
some refs : getOriginal() Jenkins-examples getCouse
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论