It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there any way to use dotenv with Bitbucket Pipelines? Edited

As the title says, is there any way to use dotenv with Bitbucket Pipelines for CI purposes, while still adding the (perhaps multiple) `(.stage).env` to .gitignore?

I know Pipeline supports environment variables, and that they can be referenced in bitbucket-pipelines.yml, but I can't figure out how to use `dotenv` files instead, and vary which file to use based on i.e. branch patterns.

For example, I'd like commits to `develop` to use `.test.env` variables, while commits to `master` instead uses the variables from `.prod.env`.

Perhaps I'm going down the wrong path? Although other websites use examples of multiple `.env` files, the library authors discourage that approach. I'm using Zeit Now for hosting, so I can't just SSH a `.env` file onto the server.

Any advice is very welcome :-)

(also asked on SO, see here for points)

1 answer

0 votes
Graham Gatus Atlassian Team Aug 30, 2018

Short of storing multiple environment files inside your repository, I like the approach mentioned in the stack overflow response of using a base64 encoded environment variables to store each file.

You could configure multiple environment variables containing the base64 encoded .env file, one per environment. The current branch is exposed via the 'BITBUCKET_BRANCH' variable, so you could use that in combination with the per environment .env variables.

Alternatively, storing the .env files in a separate git repo would also work - you could then clone the repo as part of your pipeline, and select the correct .env file to use based on BITBUCKET_BRANCH.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

957 views 1 16
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you