Prodinit Software Solutions
LinkedinGithub
  • Prodinit's Engineering Blog
  • aws
    • Ways to delete AWS ECR images
    • Enable Cloudwatch Alarm and SNS Topic for AWS Billing Alert
    • A-Z of AWS VPC and other services - with Terraform
    • How Internet Works?
    • How to download/view code running in your lambda functions?
  • backend engineering
    • What is idempotency?
  • databases
    • Database Optimisation - Indexing vs Sharding with Postgres and Django ORM examples
  • devops
    • Docker Best Practices
    • Docker Networking - Bridge vs Host vs Overlay
    • A comparision between multistage build and singlestage build in Docker
    • Things to remember before building your first blue/green deployment in Kubernetes
    • How to export env variables in circleci? (You wont find this in circleci documentation)
  • frontend engineering
    • Host your static website with s3, CloudFront, Route53, and domain from godaddy in 4 easy steps
  • product management
    • You'll fail as a lead developer, here's why ...
  • python
    • Achieve Peak Performance in Python
    • Play with List of dictionaries in Python
    • How we develop a custom autoscaling metrics based on number of tasks in the queues?
  • Contact Us
    • Who are we?
    • Work with us.
Powered by GitBook
On this page
  1. devops

How to export env variables in circleci? (You wont find this in circleci documentation)

PreviousThings to remember before building your first blue/green deployment in KubernetesNextHost your static website with s3, CloudFront, Route53, and domain from godaddy in 4 easy steps

Last updated 1 year ago

According to the circleci documentation i should echo commands into $BASH_ENV in order to interpolate variables

echo 'export TF_VAR_ENVIRONMENT="${ENVIRONMENT}"' >> $BASH_ENV

Unfortunately, does not seem to work.

Solution: we have to explicitly do source $BASH_ENV before each job that relies on it

jobs:
    job-name:
        executor:
            name: python/default
            tag: '3.9'
        steps:
        - checkout
        - run:
            name: source bash env
            command: |
                echo 'export TF_VAR_ENVIRONMENT="${ENVIRONMENT}"' >> $BASH_ENV
                source $BASH_ENV

Each step runs in its own shell, so if you have commands that depend on runtime definition of an environment variable, your only option is to combine those commands into a single step.

Note: BASH_ENV is purely bash-thing. So for example if you use alpine based docker image, which has dash by default, it will not work.

Written by -

Tags

Enjoyed the blog? If so, you'll appreciate collaborating with the minds behind it as well.

Dishant Sethi