passing Environment variables between tasks
Asked by David Desjardins:

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


Answers:
author: Eduardo Alvarenga
body: Hello [@David Desjardins](/t5/user/viewprofilepage/user-id/5103534),

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:

* [Configuring a variables task](https://confluence.atlassian.com/bamboo/configuring-a-variables-task-687213475.html)

Thank you,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: David Desjardins
body: 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.


author: Eduardo Alvarenga
body: Hello [@David Desjardins](/t5/user/viewprofilepage/user-id/5103534),

Thank you for the provided context.

You have to use the Inject Bamboo variables task for that. Simply follow these steps:

* On a task, create your password file using the "key=variable" format. How you are generating the string doesn't matter, as long you create a text file that can be later loaded by Bamboo
  *

    ```
    echo my_password=abc123 > secret.txt
    ```

* Add an Inject Bamboo variables task and load the **secret.txt** file, make sure to select Scope as **Result**
* Load the variable as *${bamboo_my_password}* (on shell scripts) or *${bamboo.my_password}* where you need

Eduardo Alvarenga  
Atlassian Support APAC


author: David Desjardins
body: Hell [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410)

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:

* pw=$(openssl rand -base64 15)  
  echo $pw  
  AVI_PASSWORD=$pw  
  echo "AVI_PASSWORD=$AVI_PASSWORD" \>secrets.txt

I then have an "**Inject Bamboo Variables** " task (see image), but I don't have a "**scope**" field.

![Screenshot 2022-12-18 at 2.12.50 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/231029i97EC7306B4EC3B79/image-size/large?v=v2&px=999 "Screenshot 2022-12-18 at 2.12.50 PM.png")

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:

**$bamboo_inject_AVI_PASSWORD**

I should be good to go once I have this corrected. Once again, Thank you so much for your help.

Thanks,

Dave


author: Eduardo Alvarenga
body: Hello [@David Desjardins](/t5/user/viewprofilepage/user-id/5103534)

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](https://confluence.atlassian.com/bamboo/bamboo-upgrade-guide-720411366.html) 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--**