I have a script task in Bamboo where I create a random password, and I'm trying to store it in an environment variable so I can access it in another task in the same pipeline. I create the password in the first task and can see it with an echo, but in the next script task, I do an "echo" of that variable, and the log produces a blank line. Is there a way to make a env variable accessible by another task
First Task - Script Body
pw=$(openssl rand -base64 15)
export DEVICE_PASSWORD=$pw
Second Task - Script Body
echo $Device_PASSWORD
Hello @David Desjardins,
Welcome to Atlassian Community!
To have one variable passed over to the next task in a Job or even on subsequent Stages of the same Plan, you need to create a properties file and load it with a "Inject Bamboo variables" task. With that, Bamboo will read the content of a text file and load it into memory.
More information here:
Thank you,
Eduardo Alvarenga
Atlassian Support APAC
--please don't forget to Accept the answer if the reply is helpful--
Hi Eduardo - Thanks for the info. I should probably give you a little more context about what I’m trying to do. For security purposes, I need to change passwords for a device every 90 days. I was hoping to fully automate this through a deployment pipeline and have cron run it every 90 days with no intervention needed. I have a forge manifest process task that changes cloud forge static secrets but in the yaml file I have a password variable placeholder. I’m trying to generate a 15 character password in an earlier task and pass it to other tasks. If I’m reading the documentation correctly, I lose the ability to automate the generation of the password. Is my thinking correct or do you know of another way I could do this? Is it possible to generate the password and pipe it to a temp file and then read it back in as a variable? I’m not great at bamboo and know how to get variables out of bamboo but not how to send them in externally. Any info would be great and thanks again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Desjardins,
Thank you for the provided context.
You have to use the Inject Bamboo variables task for that. Simply follow these steps:
echo my_password=abc123 > secret.txt
Eduardo Alvarenga
Atlassian Support APAC
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hell @Eduardo Alvarenga
Thank you so much for your help on this, as I'm one step away from making this happen, and I was hoping you could help me with the last part. I did what you said and created a "Script Task" with this:
I then have an "Inject Bamboo Variables" task (see image), but I don't have a "scope" field.
So the question I have is, will this still work, and if so, I'm having a hard time accessing the AVI_PASSWORD variable in other "Forge Manifest Processor" Tasks - I have been trying to access the variable like this:
I should be good to go once I have this corrected. Once again, Thank you so much for your help.
Thanks,
Dave
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Desjardins
Thank you for the extra details.
"Scope of the variables" was introduced in Bamboo 7.0. As you don't have that option I assume you are using an earlier version of Bamboo -- I highly recommend you plan an upgrade as soon as possible.
The steps you have provided so far are accurate. If all your tasks are contained on the same Bamboo Job, the bamboo_inject_AVI_PASSWORD variable will be passed over to the next tasks within the same Job. But, if you want to use that variable within different stages, you need to have the variable set at the "Result" scope level, only present on Bamboo 7.0+.
Eduardo Alvarenga
Atlassian Support APAC
--please don't forget to Accept the answer if the reply is helpful--
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.