如何在 Jenkins 中使用条件语句 'Options'块



我正在尝试基于变量设置Jenkins管道作业的超时时间。

我得到了这样的东西:

pipeline {
agent any
options {
timeout(time:6, unit:'HOURS')

}
}

我希望这个超时只在变量为true时设置。像这样:

pipeline {
agent any
options {
if (timerCause) {
timeout(time:6, unit:'HOURS')
}
}
}

我不能在选项块中的ifwhen语句中这样做。任何提示都会很好。谢谢:)

如果没有设置标志,那么设置一个默认值如何?

def flag = false
def to = Integer.MAX_VALUE
if(flag) {
to = 500
}
pipeline {
agent any
options {
timeout(time:to, unit:'SECONDS')
}

不知道timerCause是什么,也不愿意猜测,我只推荐三元运算符:

pipeline {
agent any
options {
timeout(time: timerCause ? 6 : 9999, unit:'HOURS')
}
}

最新更新