Reuse and rename workspace variables as repository variables or deployment variables
Asked by Bence:

I have access keys and secrets defined as bitbucket workspace secret variables. One variable pair for dev and one for prod environment:

*** ** * ** ***

**![Screenshot_20230703_124845.png](https://community.atlassian.com/t5/image/serverpage/image-id/266300i3C6ABD84206F5ECB/image-size/large?v=v2&px=999 "Screenshot_20230703_124845.png")**

*** ** * ** ***

Our system admin manages and rotates these keys, and multiple repositories utilizes these in the pipeline.

In one of the repos I'd like to reuse the DEV postifxed variables without the postfix, as repository variables.

I tried to do this in *Settings/Pipelines/Repository variables* page with defining the next variables:

* **AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID_DEV**
* **AWS_SECRET_ACCESS_KEY: $** **AWS_SECRET_ACCESS_KEY_DEV**

*** ** * ** ***

![Screenshot_20230703_125035.png](https://community.atlassian.com/t5/image/serverpage/image-id/266301iE35D21CE7C150583/image-size/large?v=v2&px=999 "Screenshot_20230703_125035.png")

*** ** * ** ***

It seems that the system does not resolve the workspace level variables in the pipeline execution.

Is it possible to do this somehow?

This would allow me to define much more generic steps in bitbucket pipeline without renaming the variables in the pipeline code.

This feature would be even more beneficial to use for configuring variables for different Deployment environments without writing specific code to handle different variable names.


Answers:
author: Aron Gombas _Midori_
body: The documentation of the [variable precedence rules](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#User-defined-variables) suggests that the repository variable *can* override the workspace variable. Which would suggest that if you don't define a variable on the repository level, then you can access the workspace-level one.

So, what if you drop those definitions from the repository variables?

comments: author: Bence
body: I'd like to reuse the workspace level variables in repository level with a different name without knowing its values.

If i drop the definitions from the repository variables I'll end up with different than expected variable names from the workspace level. (actual variable: AWS_ACCESS_KEY_ID_DEV instead of expected: AWS_ACCESS_KEY_ID). So again I end up to redefine/rename these in the pipeline script, what I'd like to avoid

Reusing in the deployment steps are even more complicated, since i need to handle both **DEV** and **PROD**postfixes in the pipeline definition script.

In some projects I have even more environments, which adds more complexiti in script, if I can't rename and reuse workspace level variables as deployment variables.


author: Aron Gombas _Midori_
body: Hmm.

I think I understand the problem, and it seems that there is no other option than injecting *both* the workspace variables and the repository variables using unique names to the pipeline script's execution context and let the script decide (depending on other variables?) which to use...


author: Bence
body: Yes, I found the same, than maybe it is a feature request:)  
Do you think I can create a feature request from this question?


author: Aron Gombas _Midori_
body: You can, sure.

(But, to stay realistic, implement the best you can with the currently available options and don't wait for Atlassian to resolve this for you.)


author: Bence
body: Sure, I'll not wait for the implementation. But at least can expect something in the future:)


author: Theodora Boudale
body: Hi [@Bence](/t5/user/viewprofilepage/user-id/2093413),

We have an existing feature request that you can vote for (by selecting the **Vote for this issue** link) here:

* <https://jira.atlassian.com/browse/BCLOUD-18699>

Kind regards,  
Theodora


author: Bence
body: Thank you for linking this here. Sure I'll vote for that:)


Tags: bitbucket-cloud

bitbucket-pipelines

repository