在我的管道中,我有一个检查特定计算机(节点)是否离线的阶段。如果是,我想跳过下一阶段。但是,下一阶段设置为使用离线代理,因此似乎无法检查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 enteringagent
in astage
By default, the
when
condition for astage
will be evaluated after entering theagent
for thatstage
, if one is defined. However, this can be changed by specifying thebeforeAgent
option within thewhen
block. IfbeforeAgent
is set to true, thewhen
condition will be evaluated first, and theagent
will only be entered if thewhen
condition evaluates to true.
关于jenkins - 如果座席离线,如何跳过一个阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58394325/