How can I set config.yml environment variables with ones setted from UI

I have a config.yml file and I set some environment variable inside of it as so

    environment:
       CREDENTIALS: "credentials.json"
       DB_PASSWORD: ${STAGING_DB_PASSWORD}

The problem is DB_PASSWORD gets the value ${STAGING_DB_PASSWORD} and not the actual password. I’ve tried also

DB_PASSWORD: $STAGING_DB_PASSWORD

without a chance. the environment variable STAGING_DB_PASSWORD is set from the UI

That might be quite simple but I don’t know how to do that.

Hi @JSmith

For the environment stanza settings, it only takes static values essentially;
The values set are taken as-is and not evaluated.
Hence, your $DB_PASSWORD env var is set to the literal string ${STAGING_DB_PASSWORD}.

You can take advantage of the $BASH_ENV env var to set up these env vars early into the job then.

Assuming you have $STAGING_DB_PASSWORD env var injected via project env vars or org contexts,

# example
jobs:
  myjob:
    docker:
      - image: cimg/base:current
    steps:
      - checkout
      - run: |
          echo 'export DB_PASSWORD="${STAGING_DB_PASSWORD}"' >> $BASH_ENV
      - run: |
          do-something-that-uses-DB_PASSWORD-env-var.sh

Ref: Using Environment Variables - CircleCI

Hope this helps!

1 Like

I already figured it out but thank you for this clear and concise explanation and solution.

Best

1 Like

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