Slug versions of merge request pipeline variables

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

Proposal

Using merge request pipelines, the predefined CI variables CI_COMMIT_REF_NAME/CI_COMMIT_REF_SLUG aren't available, being replaced by CI_MERGE_REQUEST_SOURCE_BRANCH_NAME. Sadly, there is no _SLUG version of that variable, so we can't easily use the branch name for docker image tags we build.

We have this CI workflow configuration:

workflow:
  # Lets make sure we run merge request pipelines for everything where we expect a merge request.
  # This allows us to use some more predefined variables (e.g. target branch)
  rules:
    # run as merge request pipeline for merge requests ...
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      variables:
        DOCKER_TAG: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME-$CI_COMMIT_SHA
    # ... or as branch pipeline for our target branches ...
    - if: '$CI_COMMIT_BRANCH =~ /^(main|release\\/.*)/'
      variables:
        DOCKER_TAG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
    # ... or as branch pipeline for all tags
    - if: '$CI_COMMIT_TAG != null'
      variables:
        DOCKER_TAG: $CI_COMMIT_TAG

As you can see, for our main and release/* branches we use the slugified branch name as component in our docker image tag, while for git tags we use them as they are and for merge requests we (used) the source branch name. This breaks with branches in the format $ticket/$very-short-desc or even just feature/some-new-feature/bugfix/nasty-bug.

Please consider adding slugified versions of the following variables, or add another way to easily slugify a variable in CI (something like ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME|slugify}?).

  • CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
  • CI_MERGE_REQUEST_TARGET_BRANCH_NAME
Edited by 🤖 GitLab Bot 🤖