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

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

Yilmaz_Akarsu March 22, 2020

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

0 votes
Radek Antoniuk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 25, 2020
  • 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.

Yilmaz_Akarsu March 25, 2020

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
AUG Leaders

Atlassian Community Events