最佳答案
我正在创建一个示例 Jenkins 管道,这里是代码。
pipeline {
agent any
stages {
stage('test') {
steps {
sh 'echo hello'
}
}
stage('test1') {
steps {
sh 'echo $TEST'
}
}
stage('test3') {
if (env.BRANCH_NAME == 'master') {
echo 'I only execute on the master branch'
} else {
echo 'I execute elsewhere'
}
}
}
}
此管道将因下列错误日志而失败
Started by user admin
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 15: Not a valid stage section definition: "if (env.BRANCH_NAME == 'master') {
echo 'I only execute on the master branch'
} else {
echo 'I execute elsewhere'
}". Some extra configuration is required. @ line 15, column 9.
stage('test3') {
^
WorkflowScript: 15: Nothing to execute within stage "test3" @ line 15, column 9.
stage('test3') {
^
但是当我执行以下示例 从这个网址时,它会成功执行并打印 else 部分。
node {
stage('Example') {
if (env.BRANCH_NAME == 'master') {
echo 'I only execute on the master branch'
} else {
echo 'I execute elsewhere'
}
}
}
我能看到的唯一区别是,在工作示例中没有 stages
,但在我的示例中有。
这里出了什么问题,有人能给点建议吗?