【问题标题】:Identify when retry happened in Jenkins pipeline确定 Jenkins 管道中何时发生重试
【发布时间】:2021-12-09 10:09:41
【问题描述】:

我已经在 J​​enkins 管道中的一些代码上实现了重试。

  retry(2) {
    // code
  }

有没有办法确定重试发生的时间?除了手动检查控制台日志。 想要识别已经重试了一些 flakey 代码并发送通知的构建。

【问题讨论】:

    标签: jenkins groovy jenkins-pipeline


    【解决方案1】:

    我不知道在 retry{ } 块内有什么方法。

    您可以尝试一个相当通用的解决方案(甚至可以作为共享管道库中的全局变量),例如使用 try catch 块(因为重试将等待异常):

    int retryAttempts = 0
    retry(2) {
      try {
        if (retryAttempts>0) {
          // a retry is occurring
          // Do pre-retry logic, if needed
          ...
        }
        // Do stuff
        .....
      } catch (e) {
        retryAttempts++ // a retry WILL occur
        throw e // rethrow to trigger retry
      }
    }
    if (retryAttempts>0) {
      // a retry has occurred
      // Do post-retry logic, if needed
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 2022-11-14
      • 1970-01-01
      相关资源
      最近更新 更多