Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Use bitbucket variables (deployment,repository..secured, non-secured) in GAE pipe.

Hi

What's the suggested way to set environment variables when using bitbucket pipelines? I.e. how can I set the bitbucket deployment variables as my applications environment variables when building? I am using the google cloud app engine pipe.

The app.yaml supports the usage of env variables per default, however, it seems like the bitbucket variables are not accessible at this point.

My app.yaml looks like this:

runtime: nodejs10
instance_class: F4_1G

env_variables
   TEST: '${TEST}'
   TEST_SECURED: '${TEST_SECURED}'

another approach was to use the script section in the bitbucket-pipelines.yaml, for example:

script:         
- echo "Deploying to GCP APP Engine"          
- echo "Setting necessary environment variables.."          
- export TEST="${TEST}"
- export TEST_SECURED="${TEST_SECURED}"

Both result in either *undefined values or not setting the env variables at all*.

Thanks for your response.

/y

 

PS: I am expecting the secret variables to be set correctly using this approach, or do I need to manually decode them using base64? Can you please provide me a working example for both cases. Preferrably using the app.yaml.

 

 

1 answer

  • if you have a single-line value for the variable, then you can just set it in the repository variables and that should work out-of-the-box
  • if you have a json file for instance, then you need to set the variable to base64 encoded value and then in the pipeline step you can do:
- echo $VARIABLE | base64 -d | docker login -u _json_key --password-stdin https://gcr.io

 Check this good article, I think it will solve most of your issues.

Thanks for the response. I would like to avoid writing a custom docker script when I can use the bitbucket pipe for google cloud app deployments:

- pipe: atlassian/google-app-engine-deploy:0.6.1

This pipe uses an app.yaml, which per default allows you to define env_variables. This is where I would like to use my secured bitbucket deployment variables. I feel like this is the cleanest solution! If only it would work...

E.g. in app.yaml:

runtime: nodejs10
instance_class: F4_1G

env_variables
:
 
NODE_ENV: '${BITBUCKET_DEPLOYMENT_ENVIRONMENT}'
  
TEST: '${MY_TEST_VARIABLE}'

As an alternative solution, setting the env variables in the script section of bitbucket pipelines would also be ok. As seen in this example:

script:
- echo "Deploying to GCP APP Engine"
- export MY_TEST='${TEST}'
- export MY_TEST_SEC=$(echo "${TEST_SEC}| base64 -d)
- pipe: atlassian/google-app-engine-deploy:0.6.1

Even though the commands get exectued and the values seem to be available (i.e. I can decode the bitbucket values on secured variables or use unsecured ones), the export variables are not set in the final image that is deployed to my app engine!

Probably has to do with the fact that the final image is the docker image, that is defined in the google app engine pipe: atlassian/google-app-engine-deploy:0.6.1. And everything before is basically a runtime-environment to help deploy the pipe? Or because this pipe is relying on the env_variables in the app.yaml - but there I dont have the bitbucket variables accessible?

Suggest an answer

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

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,230 views 0 3
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