I am trying to set an environment variable for my GitLab Runner based on the branch that the commit originated from.
I have 4 kubernetes clusters: staging, integration, production, and qa. Essentially I want to deploy my application to the proper cluster based on the branch I am pushing to.
image: google/cloud-sdk:latest
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
- docker info
stages:
- publish
publish:
stage: publish
script:
- if [ "$CI_COMMIT_REF_NAME" = "master" ]; then $ENVIRONMENT="production"; else $ENVIRONMENT="$CI_COMMIT_REF_NAME"; fi
- echo $ENVIRONMENT
.
.
.
- kubectl apply -f cfg/${ENVIRONMENT}/web-deployment.yaml
only:
- master
- integration
- qa
- staging
Any time I run my script with a different form of the if statement I get the following error:
/bin/bash: line 83: =integration: command not found
ERROR: Job failed: exit code 1
So from what I can tell the variable is being set, but the script exits. I've seen several SO questions related to this problem, but nothing about how to set a variable and then continue a script. How can I fix this issue?