Pipeline job: support retry value as string

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

Proposal

I'd like to propose the possibility to be able to control the number of job retries through a variable.

Currently it is not possible to control the amount of retries for a job in a more dynamic fashion. Trying to use a variable as a value results in an error message This GitLab CI configuration is invalid: retry config has to be either an integer or a hash.

The use case for this problem is that if you have multiple jobs you might want to be able to easily change the amount of retries these jobs will perform. In larger pipelines there could be many jobs with different retry settings. Changing them all manually is a lot of work and it would be nicer if we were able to set them by using a variable instead of a fixed value.

The problem is that variables that are either globally defined or set when manually starting a pipeline are treated as strings. There isn't a way to force a specific type on a variable.

I'd like to be able to use a pipeline configuration similar to the following (which is invalid with GitLab 15.5):

variables:
  RETRIES: 2

first job:
  image: alpine
  script:
    - uname -a
  retry: ${RETRIES}

second job:
  image: alpine
  script:
    - uname -a
  retry: ${RETRIES}

In !98100 (closed) I hopefully was able to identify the correct place to make a change (lib/gitlab/ci/config/entry/retry.rb).

Edited by 🤖 GitLab Bot 🤖