How to write secured env variables into file inside docker image in pipelines?

I'm trying to build a pipeline to deploy our serverless architecture. Ideally I can right into a local .env file including all several secured environment variables. I'm assuming the entire docker image is flushed after the pipeline is done deploying so this is really not a security concern. 

However, when I try to write into the file, all env vars write ok except the secured ones. Any idea how to make this work? 



# setup local .env file
- touch .env
- echo "DEV_DB_HOST=$DEV_DB_HOST" >> .env
- echo "DB_LOGGING=true" >> .env
- echo "SLS_DEBUG=*" >> .env


Where ```$DEV_DB_PASSWORD``` is a secured variable. 


Thank you!

2 answers

1 accepted

Oh Yes. No errors. What actually happens is all the normal environment variables gets written as expected. The secured ones translate into the string itself,

so this line:


will show as the following line:

DEV_DB_DATABASE=<name of the db from the env var>
BUT this line:


will result in the following line literally:


I'm assuming this is some sort of a security mechanism to not 'log' the secured vars but I wonder if there's a way around it or if I'm just doing something wrong. Ideally we actually write the value of the secured vars into the same file so we can then use it in our deploys.


How are you verifying the contents of the file? If you're running "$ cat .env" (or something similar) within Pipelines, then we will be masking the variable when it is printing from the file. But it should still be in the file as the correct value.

I've tested out a similar example here:!/results/1387

The value of "$SECRET" is "cat". (When I do echo "$SECRET" | wc -m, there's is also a new line character which is why it's 4 and not 3).

Does any of that help?

Ok, this helped. Yes, I was checking with 'cat' - that was confusing. 

I changed it a bit and it is now working the way we need it. Thanks!

Awesome! :)

0 votes

Can you explain more on the problem you're having with the secured variables? Are you getting an error when you write it into the file?



Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

649 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot