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

How to reference account variables from deployment variables?

andriesvanhumbeeck December 30, 2019

Is it possible to reference account variables from deployment variables?

The use case is the following:

- I have multiple repositories which uses the same set of secrets for each Dev, Staging and Production environments. (so 1 set per env)

- Instead of specifieng these in each repository again (duplication), I add the generic Dev, Staging and Prod keys to Account Variables.

- I would like to do the following in 'Deploymenent Variables': GOOGLE_SECRET = $GOOGLE_SECRET_DEV (if deployment stage is 'DEV') or GOOGLE_SECRET = $GOOGLE_SECRET_STG (if deployment stage is 'Staging'). - Where GOOGLE_SECRET_DEV is specified as Account variable.

This way I, able to reuse 'steps' more easyly because I can now use the generic GOOGLE_SECRET, instead of defining different steps for each env.

1 answer

0 votes
ktomk
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.
January 5, 2020

I'm not aware about a generic variable reference feature inside Atlassian Bitbucket Cloud Pipelines plugin specifically.

However as far as a POSIX compatible shell is at your option (e.g. a pipeline step script), the shell has it covered:

- eval "GOOGLE_SECRET=\${$GOOGLE_SECRET_ENV}"; export GOOGLE_SECRET

Where GOOGLE_SECRET_ENV is "GOOGLE_SECRET_DEV" or "GOOGLE_SECRET_STG" respectively.

If you follow a specific naming convention, the BITBUCKET_DEPLOYMENT_ENVIRONMENT variable might be of use to make this kind of mapping even more implicit. It has the name of the deployment environment as configured. So you can have "preconfigured" environments from the account variables.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events