I’m very new to CircleCI, and have inherited a partially completed setup that has some shortcomings. As of now, I am trying to start a PowerShell command with different parameters based on the branch name. Problem is that the environment variable seems to be empty in the PowerShell step. I have a debug-step above where I verify that the variable is set, and in that step the variable is populated as expected.
This is a slightly simplified version of my pipeline. What am I doing wrong?
name: Set AppServers
if [ "$CIRCLE_BRANCH" == "dev" ]; then
echo "export APP_SERVER01=devServer" >> $BASH_ENV
elif [ "$CIRCLE_BRANCH" == "test" ]; then
echo "export APP_SERVER01=testServer" >> $BASH_ENV
elif [ "$CIRCLE_BRANCH" == "prod" ]; then
echo "export APP_SERVER01=prodServer" >> $BASH_ENV
name: Verify string interpolation etc
command: echo "Value of AppServer01 is $APP_SERVER01" # This prints correct value
name: Run pre-deploy
$App_Server01 = $env:APP_SERVER01;
Write-Host "App_Server01: $App_Server01, env:APP_SERVER01: $env:APP_SERVER01" # This prints empty values
Any help would be appreciated, Chat GPT has already given up, and as far as I can tell from the documentation this should work. Unless this specific case is not supprted for some reason…
No, CIRCLE_BRANCH is populated, though I had not thought about potential other ways of triggering the pipeline. Thanks for that headsup The variable that is not populated is APP_SERVER01. I have tried to illustrate when it is populated in the code snippet.
I was able to find a workaround by moving the if/else statements into the “Run pre-deploy” step and hard coding the values for APP_SERVER01 into the statements. However, this is a pretty messy way of doing things, especially since I have more steps where I want to use the same environment variable and several variables (the code snippet is just for illustration).
Leaving this question open