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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,883
Community Members
 
Community Events
176
Community Groups

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

Atlassian Community Events