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

How can I have environment variables that are set through a script be persistent in a Bamboo job?

Caleb Tote February 25, 2014

We have several environment variables that are set for each version of our build. Because of this, we have scripts that run which update the variables, and then future scripts use these variables as part of the build.

How can I make the variables that are set from Script A persistent so that they are accessible by Script B? I can see in the log something along the lines of:

  • set COMPFILE=comps.dat

But, when Script B is executed, I get the following error:

  • environment variable COMPFILE not set! (check setenv.cmd)

-----------------

I just tried setting the COMPFILE variable in my global variables for Bamboo, and I STILL get this error:

26-Feb-2014 12:42:54C:\Users\ctote\bamboo-home\xml-data\build-dir\MOM-CPP-JOB1>ratlperl make.pl -ACTION=DEPEND

26-Feb-2014 12:42:54environment variable MOM_COMPFILE not set! (check setenv.cmd)

26-Feb-2014 12:42:54Aborting script make.pl!

I'm starting to wonder if Bamboo is the right product for our company. Any help is appreciated.

3 answers

0 votes
John Bowker February 25, 2014

You can try the Bamboo Inject Variables Plugin. This allows you to manage variables in your plan:

https://marketplace.atlassian.com/plugins/com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin

Your other option would be to dump variables to a simple db and read them back.

Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2014

For every bamboo task, yes, but not if they are in the same script task.

A script is written out to a temporary .bat and run (.ps1 for Powershell option)

Caleb Tote February 25, 2014

I'm not entirely sure this will solve our problem. We want access to the variables we set during the task that runs this perl script. The plugin looks like it just makes some things available throughout Bamboo, but not necissarily in the scripts you run?

If I do:

call setenv.cmd

ratlperl make.pl

It's like my make.pl has no clue what was set during setenv.cmd... Does bamboo launch a new shell for every task? That seems a bit absured, but I guess it's possible?

Caleb Tote February 25, 2014

Hm, ok then I'm somewhat confused as to why my variables aren't being recognized. Or also, if they are recognized during make.pl , they show paths as ${bamboo.mypath}/comps.dat

If I set my variables during the same task, such as:

Global Variable:
workspace : ${bamboo.capability.build-dir}\${bamboo.buildKey}

My Inline Script:
:: where the c++ code resides
set CODE_PATH=${bamboo.workspace}

Then, when I kick off a perl script in the same task I get:
make.pl Could not open data file : '${bamboo.capability.build-dir}/${bamboo.buildKey}/comps.dat' – Aborting script!

Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2014

Where is that Global variable? Bamboo doesn't support nested variables natively.

Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2014

You'll need the Nested Variables for Bamboo plugin if you want nested variables.

0 votes
Caleb Tote February 25, 2014

This isn't really an option for us - since we don't want to be permanently setting the variables every time we do a build. Is there really no alternative here?

0 votes
Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2014

Environment variables set in a script or command line only exist for that session, it doesn't directly relate to Bamboo or any CI tool. To set an environment variable permanently, you'll have to use setx or modify the registry and broadcast it yourself.

setx has a slightly different format

setx COMPFILE comps.dat

Caleb Tote February 25, 2014

This isn't really an option for us - since we don't want to be permanently setting the variables every time we do a build. Is there really no alternative here? I mean, I have the .cmd file in the same script task as the call to our make.pl file - is Bamboo really executing those in two separate command shells?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events