Answer the question
In order to leave comments, you need to log in
Gitlab CI. How to set different values of variables for different branches?
I tried to solve the problem like this:
image: alpine
variables: &global_variables
ENV_VARIABLE: ${VAR_$CI_COMMIT_BRANCH}
stages:
- test
test_job:
stage: test
variables:
<<: *global_variables
script:
- echo "This job ran on the $CI_COMMIT_BRANCH branch."
- echo "$CI_COMMIT_BRANCH - $ENV_VARIABLE"
Answer the question
In order to leave comments, you need to log in
You can use rules for this .
build-container:
stage: build
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
variables:
image_tag: "$CI_REGISTRY_IMAGE"
changes:
- Dockerfile
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
variables:
image_tag: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
changes:
- Dockerfile
services:
- docker:18-dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build --pull -t ${image_tag} .
- docker push ${image_tag}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question