如何在我的Jenkinsfile中指定类似以下内容的内容?
当分支不是x
我知道如何指定分支特定的任务,例如:
stage('Master Branch Tasks') {
when {
branch "master"
}
steps {
sh '''#!/bin/bash -l
Do some stuff here
'''
}
}
但是,我想为分支不是主节点或暂存阶段指定一个阶段,如下所示:
stage('Example') {
if (env.BRANCH_NAME != 'master' && env.BRANCH_NAME != 'staging') {
echo 'This is not master or staging'
} else {
echo 'things and stuff'
}
}
但是,以上方法不起作用,并因以下错误而失败:
WorkflowScript: 62: Not a valid stage section definition: "if
WorkflowScript: 62: Nothing to execute within stage "Example"
我尝试失败的注释来源:https : //jenkins.io/doc/book/pipeline/syntax/#flow-control
解决此问题后,您现在可以执行以下操作:
stage('Example (Not master)') {
when {
not {
branch 'master'
}
}
steps {
sh 'do-non-master.sh'
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句