gpt4 book ai didi

jenkins - 中止 Jenkins 管道中的当前构建

转载 作者:行者123 更新时间:2023-12-02 07:10:34 30 4
gpt4 key购买 nike

我有一个具有多个阶段的 Jenkins 管道,例如:

node("nodename") {
stage("Checkout") {
git ....
}
stage("Check Preconditions") {
...
if(!continueBuild) {
// What do I put here? currentBuild.xxx ?
}
}
stage("Do a lot of work") {
....
}
}

如果不满足某些先决条件并且没有实际工作要做,我希望能够取消(而不是失败)构建。我怎样才能做到这一点?我知道 currentBuild 变量可用,但我找不到它的文档。

最佳答案

您可以将构建标记为已中止,然后使用 error导致构建停止的步骤:

if (!continueBuild) {
currentBuild.result = 'ABORTED'
error('Stopping early…')
}

在阶段 View 中,这将显示构建在此阶段停止,但整个构建将被标记为中止,而不是失败(请参阅构建 #9 的灰色图标):

Pipeline Stage View

关于jenkins - 中止 Jenkins 管道中的当前构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42667600/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com