Using Workspace variables in deployment variables

Alan Wolman March 12, 2022

We have a number of keys that are used by all of our builds (but are different for each of our environments) and we would like to store these as workspace variables - but expose these in each of our deployments by referencing the workspace variables.


e.g.

Workspace Variables
  PROD_KEY
  STAGING_KEY
  DEV_KEY

Deployments
   Dev:
      KEY=$DEV_KEY
   Staging:
      KEY=$STAGING_KEY
   Production:
      KEY=$PROD_KEY 

script:
   - echo $KEY


Is there any way of having a deployment variable reference a workspace variable?

1 answer

0 votes
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2022

Hey Alan!

I have just tested on my end and can confirm the exact configuration you have defined will work to reference workspace-level variables IF those workspace-level variables are unsecured, as you are able to reference both deployment/workspace variables when running a pipelines build.

For more information please refer to the following link:
https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/

Cheers!

- Ben (Bitbucket Cloud Support)

Ben Orgil July 11, 2022

The variables the user asked about were "KEYS" so they probably need to be secured.

Your saying this won't work for secured workspace variables?

Is there just a way to define environments at the workspace level?

Like Drew Heasman likes this
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 12, 2022

Hey Ben,

Yes, the idea behind "secured" variables is that they are secure and therefore echoing them will not reveal the values inside these.

There is some text when configuring workspace variables from within Workspace Settings > Pipelines > Workspace Variables that defines the above:

Environment variables added at the workspace level can be accessed from all repositories that are within that workspace. To access a variable, put the $ symbol in front of its name. For example, access AWS_SECRET by using $AWS_SECRET. 
Workspace variables can be overridden by variables added on the repository level.

If you want the variable to be stored unencrypted and shown in plain text in the logs, unsecure it by unchecking the checkbox.

Environments can only be defined at the repository level from within Repository Settings > Pipelines > Deployments.

Cheers!

- Ben (Bitbucket Cloud Support)

Like Douglas Carmo likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events