Unable to expand variables in the 'image' field

Using variables inside of the gitlab-ci yaml file, allows for better re-use and cleaner files. However in the 'image' directive, these are harder to use, as certain 'expected' feature no longer work.

For one, variable substiution is not working:

image: "${CI_JOB_NAME}"

works, but

image: "${CI_JOB_NAME##*_}"

does not

Likewise

variables:
  - JOB_ID: "${CI_JOB_NAME##_}"
before_script:
  - export JOB_ID "${CI_JOB_NAME##_}"

both don't help as the image 'was already expanded'.

All of this reduces the available flexibility when re-using jobs.

For the variables, especially in the global space, it's expect-able, CI_JOB_NAME does not yet exist when these are determined. But even when having job-level variables, this does not work.

It may be as trivial as that the image directive is evaluated too early, or simple the parser does not allow for shell substitution.

Some searching did show this old post on the forums, which of course indicates the same thing, variable expansion in the image directive: https://forum.gitlab.com/t/how-to-use-variable-name-trimming-in-image-section-of-yml/21312

Edited by Olliver Schinagl