Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

export variables beetween step

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

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

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 

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?

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
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

236 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you