我试图使用以下代码执行构建,最后,在构建成功时执行构建后操作。仍然,我得到了MultipleCompilationErrorsException,说我的try块不是有效的节定义。请帮忙,我尝试了很多重组障碍,但似乎无法解决问题。
#!/usr/bin/env groovy pipeline{ agent any try { stages{ stage("Parallel 1") { steps { parallel ( 'firstTask' : { build( "DSL-Controll-Demo-Fibonacci-1" ) }, 'secondTask' : { build( "DSL-Controll-Demo-Fibonacci-2" ) } ) } } stage("Feature") { steps { build( "DSL-Controll-Demo-Fibonacci-5" ) build( "DSL-Controll-Demo-Fibonacci-6" ) } } stage("Parallel 2") { steps{ parallel ( "thirdTask" : { build( "DSL-Controll-Demo-Fibonacci-3" ) }, "forthTask" : { build( "DSL-Controll-Demo-Fibonacci-4" ) } ) } } } } catch(all) { currentBuild.result = 'FAILURE' } if(currentBuild.result != 'FAILURE') { stages{ stage("Post Build") { steps { build("DSL-Controll-Demo-Fibonacci-7") } } } } }
您使用的是声明式的方式来指定管道,因此您不得使用try / catch块(用于脚本化管道),而应使用post部分。参见:https : //jenkins.io/doc/book/pipeline/syntax/#post- conditions