如何在我的Jenkinsfile中指定类似以下内容?
当分支不是x时
我知道如何指定分支特定任务,如:
stage('Master Branch Tasks') {
when {
branch "master"
}
steps {
sh '''#!/bin/bash -l
Do some stuff here
'''
}
}
但是,当分支不是master或staging时,我想指定一个阶段,如下所示:
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
发布于 2017-07-10 16:30:15
解决此issue后,您现在可以执行以下操作:
stage('Example (Not master)') {
when {
not {
branch 'master'
}
}
steps {
sh 'do-non-master.sh'
}
}
发布于 2017-04-24 20:10:56
你的文章中的链接显示了一个带有脚本管道语法的示例。您的代码使用声明性管道语法。要在声明性中使用脚本化管道,您可以使用脚本步骤。
stage('Example') {
steps {
script {
if (env.BRANCH_NAME != 'master' && env.BRANCH_NAME != 'staging') {
echo 'This is not master or staging'
} else {
echo 'things and stuff'
}
}
}
}
https://stackoverflow.com/questions/43578528
复制相似问题