Modifiy variable values in gitlab-ci.yml

Viewed 59

Let's say

CI_COMMIT_BRANCH=abc/xyz

And .gitlab-ci.yml

variables:
  VAR: ${CI_COMMIT_BRANCH}

Is there a way to remove 'abc/' from the value of CI_COMMIT_BRANCH within the .gitlab-ci.yml so that the value of VAR finally becomes 'xyz'?

1 Answers

Check if the workaround described in issue 27921 could work:

variables:
  CI_SHORT_COMMIT_SHA: '$${CI_COMMIT_SHA:0:8}'
  FOO_BAR: '$${FOO}-$${BAR}'

before_script:
  - eval export CI_SHORT_COMMIT_SHA=${CI_SHORT_COMMIT_SHA}
  - eval export FOO_BAR=${FOO_BAR}

test:
  script:
    - echo ${CI_SHORT_COMMIT_SHA}
    - echo ${FOO_BAR}

In your case:

variables:
  VAR:  $$(eval echo "${CI_COMMIT_BRANCH}" | sed "s,^.\+\?/,," ) 

before_script:
  - eval export VAR=${VAR}

test:
  script:
    - echo ${VAR}
Related