gpt4 book ai didi

jenkins - 如果座席离线,如何跳过一个阶段?

转载 作者:行者123 更新时间:2023-12-05 03:57:43 27 4
gpt4 key购买 nike

在我的管道中,我有一个检查特定计算机(节点)是否离线的阶段。如果是,我想跳过下一阶段。但是,下一阶段设置为使用离线代理,因此似乎无法检查When子句。

这是我的管道的简化版本:

pipeline {
agent none

environment {
CONTINUERUN = true
}

stages {
stage('Check Should Run') {
agent any
steps {
script {
CONTINUERUN = false
}
}
}

stage('Skip this stage') {
agent {
label 'offlineAgent'
}
when {
expression {
CONTINUERUN
}
}
steps {
//Do stuff here
}
}
}
}

当我运行它时,构建只是卡在“跳过此阶段”阶段。我假设,因为代理离线。当已知代理处于离线状态时,如何跳过此阶段?

最佳答案

为了在分配代理之前评估表达式,您需要将 beforeAgent 指令添加到 when block 。

documentation的相关部分:

Evaluating when before entering agent in a stage

By default, the when condition for a stage will be evaluated after entering the agent for that stage, if one is defined. However, this can be changed by specifying the beforeAgent option within the when block. If beforeAgent is set to true, the when condition will be evaluated first, and the agent will only be entered if the when condition evaluates to true.

关于jenkins - 如果座席离线,如何跳过一个阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58394325/

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