'Modifiy variable values in gitlab-ci.yml
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'?
Solution 1:[1]
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}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
