我正在創建一個樣本詹金斯管道,這裏是代碼。詹金斯管道如果還沒有工作
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') {
^
但是,當我執行下面的例子from this url,它成功地執行並打印else部分。
node {
stage('Example') {
if (env.BRANCH_NAME == 'master') {
echo 'I only execute on the master branch'
} else {
echo 'I execute elsewhere'
}
}
}
唯一的區別我可以看到的是,在工作示例沒有stages
但對我來說是這樣。
這裏有什麼錯,任何人都可以請建議?
謝謝你這麼多,一爲答案,+1聲明管線和腳本管道,一爲REST API的建議。實際上,我需要如果和其他這就是爲什麼我使用它。 – Shahzeb