Hello, I am trying to use a CircleCI configuration with two different environments, master and production which are two different servers.
I have created my env variables in the configuration of the project, and I can invoke them using
${SERVER_PRODUCTION_USERNAME}
${SERVER_PRODUCTION_IP}
${SERVER_DEVELOP_USERNAME}
${SERVER_DEVELOP_IP}
This is what I am trying to do
- run:
name: "Setup custom environment variables"
command: |
SU=SERVER_${CIRCLE_BRANCH^^}_USERNAME
SI=SERVER_${CIRCLE_BRANCH^^}_IP
echo 'export SERVER_USERNAME=${!SU}' >> $BASH_ENV; source $BASH_ENV;
echo 'export SERVER_IP=${!SI}' >> $BASH_ENV; source $BASH_ENV;
echo ${SERVER_USERNAME} # This works
- run:
name: "What was my custom environment variable?"
command: |
echo ${SERVER_USERNAME} # This does not work
Use the name of the branch to identify the env variable, add it to the bash env and then use it during the execution on the next steps
The problem is that first echo ${SERVER_USERNAME} works and the seconds prints an empty variable, how can I fix it???