私はJenkinsパイプラインの条件付きステージに相当するものを前のステージのtry/catchを使用してレプリケートしようとしています。条件付きステージをトリガーします。ジェンキンスパイプライン - 特定のステージと後続の条件付きステップでキャッチしよう
成功のvarをSUCCESSまたはFAILEDに設定するtry catchブロックがあります。これは後でwhen文の一部として(条件付きステージの一部として)使用されます。次のように
私が使用していたコードは次のとおりです。
pipeline {
agent any
stages {
try{
stage("Run unit tests"){
steps{
sh '''
# Run unit tests without capturing stdout or logs, generates cobetura reports
cd ./python
nosetests3 --with-xcoverage --nocapture --with-xunit --nologcapture --cover-package=application
cd ..
'''
currentBuild.result = 'SUCCESS'
}
}
} catch(Exception e) {
// Do something with the exception
currentBuild.result = 'SUCCESS'
}
stage ('Speak') {
when {
expression { currentBuild.result == 'SUCCESS' }
}
steps{
echo "Hello, CONDITIONAL"
}
}
}
}
次のように私は受け付けており、最新の構文エラーがある:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed:
WorkflowScript: 4: Expected a stage @ line 4, column 9.
try{
私はバリエーションの多くをも試みました。
私はここで間違ったアプローチをとっていますか?これはかなり一般的な要件のようです。
ありがとうございました。
あなたは宣言的パイプラインを使用していますが、これは 'try' /' catch'のようなGroovyコードを実行することはできません。 – StephenKing