首先,感谢您对我的关注。
我在管道下面。
Data Source={C:/Users/Dan/AppData/LocalLow/Gravia Software, LLC/Gravia/exampleDatabase.db};
我的目标是:
现在,我可以对catch块进行第一步了。并且,停留在step2。您能否指导如何捕获阶段结果并报告失败的阶段。
答案 0 :(得分:0)
最后,我设法捕获了所有阶段结果并过滤了失败的阶段。现在,我可以围绕它写条件了。这就是我所拥有的。
#!/usr/bin/env groovy
rstages=[:]
pipeline {
agent any
stages {
stage(‘one’) {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
bat '''
echo “stage one”;
exit 1;
'''
script{
echo "stage name is: ${env.STAGE_NAME}"
echo "RESULT: ${currentBuild.result}"
}
} //catch
}//steps
post {
always {
script{
println "RESULT: ${currentBuild.result}"
println "current stage name is: ${env.STAGE_NAME}"
rstages."${env.STAGE_NAME}" = "${currentBuild.result}"
}
}
}
}//stage 1
stage('RunParallel') {
parallel {
stage(‘two’) {
steps {
bat '''
echo “stage two”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
post {
always {
script{
println "current stage name is: ${env.STAGE_NAME}"
rstages."${env.STAGE_NAME}" = "${currentBuild.result}"
}
}
}
}
stage(‘three’) {
steps {
bat '''
echo “stage three”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
post {
always {
script{
println "current stage name is: ${env.STAGE_NAME}"
rstages."${env.STAGE_NAME}" = "${currentBuild.result}"
}
}
}
}
stage(‘four’) {
steps {
bat '''
echo “stage four”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
post {
always {
script{
println "current stage name is: ${env.STAGE_NAME}"
rstages."${env.STAGE_NAME}" = "${currentBuild.result}"
}
}
}
}
}//parallel
}//runParallel
stage(‘validate’) {
steps {
script{
//println RESULT: "${currentBuild.result}"
//println "stage name is: ${env.STAGE_NAME}"
println "Printing all stage results"
rstages.each{entry -> println "$entry.key=$entry.value"} // to print all elements in map object rstages
}
script{
//help: https://www.baeldung.com/groovy-maps
println "printing failed stages"
def fstages=rstages.findAll{ key, value -> value.contains('FAIL') } //to print all keys matching a value FAILURE
println fstages
}
}
post {
always {
script{
println "current stage name is: ${env.STAGE_NAME}"
rstages."${env.STAGE_NAME}" = "${currentBuild.result}"
}
}
}
}
stage(‘five’) {
steps {
bat '''
echo “stage 5”;
exit 0;
'''
}
}
}
post {
always {
bat '''
echo ‘I will always execute this!’
'''
}
}
}