In my Jenkins pipeline, I have the following Jenkins step constructed using Jenkins scripted syntax. Its purpose is to run a docker container, which runs some integration tests. I currently spawn 11 of these steps in parallel.
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!"
}
}
}
}
}
}
As you can see, I want my docker-compose
command to retry once if the docker-compose
command fails. However, if this process (including a potential retry) exceeds 15 minutes, I want a timeout error to be thrown. If a timeout error is thrown, I would all of this to be retried once more.
However, the above desired steps are not happening.
Currently, when my docker-compose
command fails on the first run, a "Timeout!" error is thrown and the whole step ends.
As you can see below, the docker-compose
command only runs for 8 minutes so a timeout error shouldn't be thrown. Also, the docker-compose
command is never retried by Jenkins.
How can I fix my Jenkins step in order to achieve my desired behaviour?
My Jenkins version is 2.270.
Edit:
Just to be clear, I expect the docker-compose
command to fail because there is a failing test inside the Docker container. However, Jenkins isn't retrying the failed docker-compose
command as expected.
I have not found anywhere any information about retry
should be > 1. Official documentation says:
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.
But it looks that in order to trigger retries it should be set to more than 1