Assigning a file type variable to a job variable unexpectedly expands the content of the file
Summary
If I assign a file type variable (defined within the CI/CD Project settings) to a job variable, the file type variable gets unexpectedly expanded.
Steps to reproduce
- Define a file variable
TEST_1='{"bla": "42"}'
within the CI/CD Project settings. - Create a
.gitlab-ci.yaml
file with the content seen in the snippet below. - Run the pipeline.
- Pipeline fails!
test variables assignment:
image: bash:latest
variables:
TEST_2: $TEST_1 # Variable TEST_1 is defined as CI/CD file variable
script:
- env |grep TEST
- |
if [[ $TEST_1 == $TEST_2 ]]; then
echo "Strings are equal!"
else
echo "Strings are not equal!"
exit 1
fi
Example Project
https://gitlab.com/mhubig/variables-test
https://gitlab.com/mhubig/variables-test/-/jobs/267062511
What is the current bug behavior?
The pipeline failes because the content of the file referenced within the $TEST_1
variable is expanded into the $TERST_2
variable.
What is the expected correct behavior?
The pipeline succeeds because the string within the $TEST_1
variable is the same as in the $TERST_2
variable.
Real world example of the problem
.deployment_job_template:
image: ${CI_REGISTRY}/docker/kubectl:latest
stage: deploy
environment:
name: ${GOOGLE_CLUSTER_NAMESPACE}
url: https://solr-master.${GOOGLE_CLUSTER_NAMESPACE}.test.com/
before_script:
- env
- gcloud auth activate-service-account --key-file ${GOOGLE_CREDENTIALS} # ERROR: This fails!
- gcloud container clusters get-credentials ${GOOGLE_CLUSTER} --region europe-west4 --project ${GOOGLE_PROJECT_ID}
script:
- cd ${CI_PROJECT_DIR}/k8s/zoo-${GOOGLE_CLUSTER_NAMESPACE}
- kubectl apply -k $(pwd)
- cd ${CI_PROJECT_DIR}/k8s/solr-${GOOGLE_CLUSTER_NAMESPACE}
- kubectl create secret docker-registry gitlab-solr-registry-auth
--namespace=${GOOGLE_CLUSTER_NAMESPACE}
--docker-server=https://registry.gitlab.test.com
--docker-username=${GITLAB_REGISTRY_USERNAME}
--docker-password=${GITLAB_REGISTRY_PASSWORD}
--dry-run -o yaml |kubectl apply -f -
deploy master branch:
extends: .deployment_job_template
only:
- master
variables:
GOOGLE_CLUSTER: hybris
GOOGLE_CLUSTER_NAMESPACE: production
GOOGLE_CREDENTIALS: ${GOOGLE_DEV_CREDENTIALS}
deploy develop branch:
extends: .deployment_job_template
only:
- develop
variables:
GOOGLE_CLUSTER: hybris
GOOGLE_CLUSTER_NAMESPACE: develop
GOOGLE_CREDENTIALS: ${GOOGLE_DEV_CREDENTIALS}
Edited by Markus Hubig