[英]How to automatically configure jenkins user input stage from remote build?
[英]How to get an id of build from which current build has restarted from stage?
我有一個 Jenkins 管道,它有 5 個階段。 假設我運行它並且它的 build id 為 5,但它在第三階段失敗了。
現在我使用Restart from failed stage
功能重新運行構建 5,當前構建使用 id 7(同時有人使用 id 6 運行)。 現在,在當前運行的 id 為 7 的構建中,我想獲取該構建已重新啟動的構建的 id(即 5)。
是否有任何 api 可以使用它獲取當前構建已重新啟動的構建 ID?
您可以通過currentBuild.rawBuild.getCause(RestartDeclarativePipelineCause)
獲取此信息:
工作管道示例:
pipeline{
agent any
stages {
stage('Stage 1') {
steps {
echoRestartedInfo()
}
}
stage('Stage 2') {
steps {
echoRestartedInfo()
}
}
}
}
void echoRestartedInfo() {
def restartCause = currentBuild.rawBuild.getCause(
org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause )
if( restartCause ) {
def originRunNumber = restartCause.originRunNumber
def originStage = restartCause.originStage
echo "Restarted from build $originRunNumber, stage '$originStage'"
}
else {
echo "Normal run"
}
}
由於使用rawBuild
,這在沙盒中不起作用。 將代碼移動到共享庫以解決此限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.