I’m seeing a strange behavior in the variables passed in my multi-project pipeline and I’m not sure if it’s a bug or a feature. I hope that someone here can clarify what’s going on.
I’m trying to pass down a URL and a filename to the downstream and I’m getting inconsistent results, depending on what I do.
In my upstream gitlab-ci.yml:
variables:
VERSION: "0.0.$CI_PIPELINE_IID"
FILE: "${CI_PROJECT_NAME}-${VERSION}.tar.gz"
URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${VERSION}/${FILE}"
stages:
- deploy
test_vars:
stage: deploy
image: bash:latest
script:
- echo $URL
- echo $FILE
trigger-downstream:
stage: deploy
trigger:
project: "my-group/downstream"
My downstream gitlab-ci.yml:
stages:
- deploy
downstream-job:
image: bash:latest
stage: deploy
environment: production
script:
- echo $FILE
- echo $URL
The output of test_vars
is what you expect. The output of downstream-job
is somewhat unexpected.
FILE contains upstream project name and downstream pipeline IID.
URL contains upstream project ID, upstream project name (in the url), downstream pipeline IID (in the version), downstream project name (in the file) and upstream pipeline IID (in the file).
Now if that’s not strange enough, we can make it even stranger.
Change the following in the upstream gitlab-ci.yml:
trigger-downstream:
stage: deploy
variables:
NEW_URL: $URL
NEW_FILE: $FILE
trigger:
project: "my-group/downstream"
And change the corresponding variables in the downstream:
downstream-job:
image: bash:latest
stage: deploy
environment: production
script:
- echo $NEW_FILE
- echo $NEW_URL
Now the output from the downstream changes!
FILE contains the downstream project name and the upstream pipeline IID.
URL contains the downstream project ID, downstream project name (in the url), upstream pipeline IID (in the version), upstream project name (in the file) and the downstream pipeline IID (in the file)
This is exactly the opposite of before.
My conclusion (for now) is that variables are expanded either in the downstream or upstream, depending on whether they have been wrapped an even or odd number of times. Which makes no sense to me.
Can someone tell me what the expected behavior is and how to consistently pass these two variables to my downstream.
I’m running on a self-managed gitlab version 15.5.4 with runner 15.5.1