我试图在Jenkins声明性管道中添加try catch block,但最终出现了以下错误,我阅读了有关为Jenkins(https://jenkins.io/doc/book/pipeline/syntax/#post-conditions)的脚本管道语法添加try catch块的文档,但我没有得到任何关于声明性语法的内容。
pipeline {
agent any
stages {
try {
stage('Checkout') {
steps {
script {
if (ci_branches.contains(env.BRANCH_NAME)) {
// Pull the code from bitbucket repository
checkout scm
}
}
}
}
}
catch(all) {
currentBuild.result='FAILURE'
}
}
}Jenkins ci构建结果
[Bitbucket] Build result notified
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 36: Expected a stage @ line 36, column 13.
try {
^
WorkflowScript: 35: No stages specified @ line 35, column 9.
stages {
^发布于 2019-05-03 03:24:04
使用声明性管道语法时,Try/catch应该在脚本中。测试以下内容:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
try {
if (ci_branches.contains(env.BRANCH_NAME)) {
// Pull the code from bitbucket repository
checkout scm
}
}
catch(all) {
currentBuild.result='FAILURE'
}
}
}
}
}
}https://stackoverflow.com/questions/55958782
复制相似问题