为什么我的 Jenkins 步骤没有重试,而是在未达到时间限制时抛出超时错误?

Why is my Jenkins step not retrying and instead throwing a timeout error when the time limit is not reached?

在我的 Jenkins 管道中,我使用 Jenkins 脚本语法构建了以下 Jenkins 步骤。它的目的是 运行 一个 docker 容器,其中 运行 是一些集成测试。我目前并行生成了其中的 11 个步骤。

node('tester') {
    stage("Test") {
        withEnv([
            "USERNAME=some_user",
            "UID=1000",
            "GID=1000"
        ]) {
            dir("some_directory") {
                // ... some steps here
                retry(1) {
                    try {
                        timeout(time: 15, unit: 'MINUTES') {
                            retry(1) {
                                sh "docker-compose --project-name tester_prod9 -f docker-compose.e2e.yml -- up --build --renew-anon-volumes --exit-code-from cypress --timeout 600"
                            }
                        }
                    } catch (err) {
                        error "Timeout!"
                    }
                }
            }
        }
    }
}

如您所见,我希望 docker-compose 命令在 docker-compose 命令失败时重试一次。但是,如果此过程(包括可能的重试)超过 15 分钟,我希望抛出超时错误。如果抛出超时错误,我会再次重试所有这些。

但是,上述所需步骤并未发生。

目前,当我的 docker-compose 命令在第一个 运行 失败时,“超时!”抛出错误,整个步骤结束。

如下所示,docker-compose 命令仅 运行s 持续 8 分钟,因此不应引发超时错误。此外,Jenkins 永远不会重试 docker-compose 命令。

如何修复我的 Jenkins 步骤以实现我想要的行为?

我的 Jenkins 版本是 2.270。

编辑:

需要说明的是,我预计 docker-compose 命令会失败,因为 Docker 容器内有一个失败的测试。但是,Jenkins 没有按预期重试失败的 docker-compose 命令。

我没有在任何地方找到任何关于 retry 的信息应该 > 1。官方 documentation 说:

retry: Retry the body up to N times
Retry the block (up to N times) if any exception happens during its body execution. 
If an exception happens on the final attempt then it will lead to aborting the build 
(unless it is caught and processed somehow). User aborts of the build are not caught.

但看起来为了触发重试应该设置为大于 1