I have a GitLab job with a bash if statement that looks like this
script:
- echo $NEW_VERSION
- export STAGE=staging
- |-
if [[ $(expr match "$NEW_VERSION", '([0-9]+)\.([0-9]+)\.([0-9]+)$') != 0 ]]; then
export STAGE=production;
fi
- echo $STAGE
The variable $NEW_VERSION
comes from a previous step. The content of this variable is a semantic version string like 1.0.0
or 1.0.1-develop.1
. If this variable is a prerelease (it contains the develop suffix) I want to set the $STAGE
to staging otherwise to production
.
My problem is that no matter which content the $NEW_VERSION
variable has, $STAGE
is always set to staging.
If I execute the script on my local mac the value is set right.
Here the log output:
$ echo $NEW_VERSION
11.0.0
$ export STAGE=staging
$ if [[ $(expr match "$NEW_VERSION", '([0-9]+)\.([0-9]+)\.([0-9]+)$') != 0 ]]; then # collapsed multi-line command
staging
Has anyone experienced a similar problem or has an idea why this solution dosen't work?