I’m trying to do a release stage using the releas-cli in a shell executer. for some reason my description and tag name are always empty.
my ref on the other hand is filled in. it is kind a strange as all three come from variables, and I have checked they are filled in.
I think the variables are expanded before the script part is run. That’s why they are empty, and $release_ver is only set within the context of the script.
I have tried both local variable and a job variable but both didn’t work. currently release_ver is a job variable, so I created the variable empty and in the script it should set the tag, due to the echo i can see the variable is set with the correct value.
The pipeline definition is generated BEFORE you define any value for release_ver
script:
- echo feature deploy
- release_ver=$(cat version.txt) # this makes the variable set ONLY in `script`, nowhere else.
- echo $release_ver
- echo $CI_COMMIT_TAG
release:
tag_name: ‘’ # empty because at the time of pipeline definition generation such variable is not defined
description: ‘' # same as above
ref: ‘$CI_COMMIT_SHA’
If you want to use variables defined in script you need to use dotenv, there is an example here
see my edit, I have created the variable before the script, and I only set the value inside de script. does this still keep it just in the context of the script?
Yes. And exactly the value is empty. Pipeline config is generated before anything from script is executed. So GitLab doesn’t know you set some value later on.
You could release via an API call, then you can first read in the text file… (edit the URL with your own Gitlab instance, if you don’t use the official one)
Yeah, I should mention that you can also call release-cli directly from script. You do not have to use the release: keyword. GitLab actually calls the command itself and passes the arguments to it, you just define it more nicely using release:.
script:
- echo feature deploy
- release_ver=$(cat version.txt) # this makes the variable set ONLY in `script`, nowhere else.
- echo $release_ver
- echo $CI_COMMIT_TAG
- release-cli --server-url https://gitlab.com --job-token=$CI_JOB_TOKEN --project-id $CI_PROJECT_ID create ...
That’s too much information at one hand lol. the example is a little bit different as the dotenv works trough multiple jobs trough artifacts, which is logic, I’m indeed using the release-cli with the shell executer, but as you mention in the answer, there are indeed a lot of possiblities, I alread use a project access token to push the newly created tag.
the release-cli in the script worked, thanks alot, very usefull information.