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

export variables beetween step

Giuseppe Sorce October 28, 2021

Hi I need to store some variables create on a step for next step.

 

- parallel:
- step:

script:
- MY_VAR="hello word"
- step
- echo "MY_VAR $MY_VAR"
- echo "MY_VAR ${MY_VAR}"

I dont't see MY_VAR on console... 
 

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 29, 2021

Hi @Giuseppe Sorce,

Variables created in one step are not available in the next steps. We have a feature request for what you are asking in our issue tracker that you can vote for https://jira.atlassian.com/browse/BCLOUD-15849

A way to work around this issue would be to write the values in a file, pass that file as an artifact, and then source the file in the next step.

Please note that in order for this to work the two steps shouldn't be parallel steps, as parallel steps cannot use artifacts produced by steps in the same parallel set. I just mention that because I see the parallel keyword in the part of the yaml file that you posted here.

An example of how this would work is the following:

pipelines: 
default:
- step:
script:
- echo export MY_VAR="hello word" >> build.env
artifacts:
- build.env
- step:
script:
- source build.env
- echo "MY_VAR ${MY_VAR}"

Please feel free to let me know if that works for you and if you have any questions.

Kind regards,
Theodora

Giuseppe Sorce October 30, 2021

Hi thank you,

it works.. but with some problems. when print or use MY_VAR  i get only "hello" and not "hello world"..but i can delete space and i think it can works very well 

Giuseppe Sorce October 30, 2021

Other question.... i need to store other variables...

 

pipelines: 
default:
- step:
script:
- echo export MY_VAR="hello word" >> build.env
artifacts:
- build.env
- step:
script:
- source build.env
- echo "MY_VAR ${MY_VAR}"
- step:
script:
- echo export MY_VAR2="hello word2" >> build.env
artifacts:
- build.env
- step:
script:
- source build.env
- echo "MY_VAR2 ${MY_VAR2}"

 

is it possible ? or next echo replace the first ?  or in the thid step have to source build.env?

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 2, 2021

Hi @Giuseppe Sorce,

Regarding the issue with spaces in variables:

I had tested that with a variable that had no spaces, I see the same issue when the variable has a value with a space like "hello word". I was able to solve this by encapsulating this in escaped quotations, like this:

- echo export MY_VAR=\""hello word\"" >> build.env

You can do the same with the other variable:

- echo export MY_VAR2=\""hello word2\"" >> build.env

Regarding additional variables:

I have tested your example yml file and I can see that it works well. The second echo command is added at the end of the build.env file, so both variables should be available in the fourth step.

However, if you want MY_VAR to be available in the third step as well, you should source the file build.env in that step. You need to source the file in every step where you want its variables to be available.

If you have any other questions, please feel free to let me know.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events