在某个阶段的所有重试尝试失败后完成整个 Jenkins 管道,而不跳过任何进一步的阶段

Complete the whole Jenkins pipeline after all the retry attempt is failed for a certain stage, without skipping any further stages

我在一个阶段内有一个重试块,尝试次数为 5。当我对该阶段的所有重试尝试都完成但结果仍然失败时,将跳过其他阶段并中止管道. 我想要的是,即使带有重试块的阶段失败,也不能跳过下一阶段,并且应该像往常一样 运行 。 到目前为止我尝试过的是,

stage('Run Test') {
try {
  echo "Hello World"
}
catch(error) {
  retry(5) {
     try {
       input "Retry?"                       
       echo "Hello World in catch"
     }
     catch(err) {
        //I want here to continue for the next stage rather than skipping the remaining stages and 
        //abort the pipeline
     }
  }
}
}

任何帮助将不胜感激。

您可以使用 retry step alongside the catchError 步骤来实现所需的功能。

catchError: Catch error and set desired build result.
If the body throws an exception, mark the build as a failure, but nonetheless continue to execute the Pipeline from the statement following the catchError step.
The behavior of the step when an exception is thrown can be configured to print a message, set a build result other than failure, change the stage result, or ignore certain kinds of exceptions that are used to interrupt the build. This step is most useful when used in Declarative Pipeline or with the options to set the stage result or ignore build interruptions.

所以你可以用 catchError 包装你的 retry 代码块,并将构建和阶段结果设置为你想要的值,以防 retry 块失败,无论结果执行将继续执行以下步骤。
类似于:

stage('Run Test') {
    echo "Hello World"
    catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
        retry(5) {
            // retry code block
        }
    }
    // following steps will always be executed
}

最常用的结果选项是:FAILURESUCCESSUNSTABLE
following answer

中查看更多选项和解释