Skip to content

Backend: CI/CD predefined variable to indicate the retry attempt

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Problem to solve

We use gitlab CI/CD pipelines to create infrastructure on Google Cloud Platform, run tests upon that infrastructure, then tear down the infrastructure thereafter. The name of the resource being created is constructed using the CI_COMMIT_REF_SLUG pre-defined variable to ensure that each execution of the CI pipeline creates uniquely named infrastructure.

Occasionally the creation of that infrastructure can fail due to external influences (e.g. failed network connectivity), when that happens we use GitLab CI's retry functionality and the retry will usually succeed.

Occasionally though the retry will fail again because the infrastructure being created has not yet been torn down from the previous failed job attempt (remember that we use CI_COMMIT_REF_SLUG to construct the name of the infrastructure resource - this will not change between retry attempts) and thus the retry fails with a name collision because GCP (obviously) does not permit two infrastructure resources to be created with the same name.

Intended users

this proposal is still WIP and not final

The proposal here would be to create a variable that keeps a newline-delimited list of retried job URLs.

When a job is retried, do something like this:

CI_RETRIED_JOB_IDS="$(printf '%s%b%s' "${CI_RETRIED_JOB_IDS:-}" "${CI_RETRIED_JOB_IDS:+\n}" "${CI_JOB_ID,+\n}")"

That would produce something like this:

CI_RETRIED_JOB_IDS='1001, 1002, 1003'

Permissions and Security

Permission to use this new predefined CI/CD variable should be consistent with existing predefined CI/CD variables.

Edited by 🤖 GitLab Bot 🤖