How to use variables from a bash script within a CircleCI config?

Hello,

I have a bash script that looks like this :-

#!/bin/bash

#!/bin/bash
username=${CIRCLE_USERNAME}
stage=$(echo "${username}" | sed 's/[^a-zA-Z]//g' | tr "[:upper:]" "[:lower:]")
echo "${stage}"

and i want to use the stage variable in my circleci job.

I am invoking the bash script like this :-

- run:
          name: "Update config file with stage name"
          command: |
            chmod 755 ./.circleci/my-script.sh

            # run my script
            ./.circleci/my-script.sh "$CIRCLE_USERNAME"
            
            sed -i "s~PLACEHOLDER~$stage~g" config.yaml

But the $stage is empty. I even tried stage=$(./.circleci/normalize-github-username.sh "$CIRCLE_USERNAME") and that did not work either. Any suggestion on how i can make it work. Thank you.

stage=$(./.circleci/normalize-github-username.sh "$CIRCLE_USERNAME") works. I just wasn’t referencing it properly.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.