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

1 vote
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.

Correct me if I am wrong but if you encode the .env files (base64), each time you want to change it like adding a new KEY=VALUE, you will need to encode the file again and store it again.

This approach looks like unfriendly and time consuming.

The other suggestion requires you to maintain 2 repositories for instead of 1 which is also complicate things.

Do you have another suggestion that is both user-friendly and simple?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Atlassian supported Jenkins integration for Bitbucket Server

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...

424 views 0 9
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you