我正在尝试跳过stage
基于常规变量,该变量值将在另一个阶段计算。
在下面的例子中,Validate
基于环境变量有条件地跳过阶段VALIDATION_REQUIRED
我将在构建/触发作业时通过它。 ---这按预期工作。
鉴于Build
即使舞台始终运行isValidationSuccess
变量设置为false
。
我尝试改变when
条件表达式如{ return "${isValidationSuccess}" == true ; }
or { return "${isValidationSuccess}" == 'true' ; }
但没有一个起作用。
打印变量时它显示为“false”
def isValidationSuccess = true
pipeline {
agent any
stages(checkout) {
// GIT checkout here
}
stage("Validate") {
when {
environment name: 'VALIDATION_REQUIRED', value: 'true'
}
steps {
if(some_condition){
isValidationSuccess = false;
}
}
}
stage("Build") {
when {
expression { return "${isValidationSuccess}"; }
}
steps {
sh "echo isValidationSuccess:${isValidationSuccess}"
}
}
}
- 在什么阶段
when
将评估状况。
- 是否可以根据使用的变量跳过该阶段
when
?
- 基于一些SO答案,我可以考虑添加条件块,如下所示,但是
when
选项看起来很干净的方法。另外,stage view
当跳过该特定阶段时,效果会很好地显示。
script {
if(isValidationSuccess){
// Do the build
}else {
try {
currentBuild.result = 'ABORTED'
} catch(Exception err) {
currentBuild.result = 'FAILURE'
}
error('Build not happened')
}
}
参考:https://jenkins.io/blog/2017/01/19/converting-conditional-to-pipeline/ https://jenkins.io/blog/2017/01/19/converting-conditional-to-pipeline/
stage("Build") {
when {
expression { isValidationSuccess == true }
}
steps {
// do stuff
}
}
when
验证布尔值,因此应评估为 true 或 false。
Source https://jenkins.io/doc/book/pipeline/syntax/#when
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)