Skip to content

Add new CI predefined variables with version components

Description

The variable CI_SERVER_VERSION available to the GitLab CI jobs looks like this 10.8.0-pre Some GitLab-CI jobs would benefit of the access to individual fields in that version number.

For example, some security product jobs are currently extracting major and minor version to choose a compatible docker image of the product to run, ex:

- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')

see https://docs.gitlab.com/ee/ci/examples/sast.html

But even this is unavailable to jobs that don't use docker-in-docker. The image field in the job definition can't use variables defined in the script portion of the job and as of now it's impossible to use, for exemple:

myjob:
  image: imagename:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR

Proposal

I propose we add the following predefined variables, exemple values for 10.8.0-pre :

  • CI_SERVER_VERSION_MAJOR 10
  • CI_SERVER_VERSION_MINOR 8
  • CI_SERVER_VERSION_PATCH 0
  • CI_SERVER_VERSION_PRERELEASE pre

Links / references

Related discussion raising the issue : gitlab-ci-yml!164 (comment 71590979)