如何在Jenkinsfile中访问重放构建的当前状态

huangapple go评论108阅读模式
英文:

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.resultcurrentResult属性,但它们返回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

huangapple
  • 本文由 发表于 2023年7月10日 23:19:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定