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

Accessing build-specific variables from script, without having to use Environment Variables box on Script Config page

Scott Goodwin June 29, 2012

I read this post, which seems to indicate that I can access build-specific variables directly from my script, instead of having to pass each one in via the Environment Variable box in the Script Configuration pane in Bamboo. I am not finding this to be the case, and am wondering if I am missing something.

Basically, I want to be able to arbitrarily access all of the following build specific variables via my perl script, which is called in a pre-build script in order to apply these values to the version in our app:

${bamboo.buildPlanName}

${bamboo.buildKey}

${bamboo.buildNumber}

${bamboo.buildResultKey}

${bamboo.buildTimeStamp}

${bamboo.repository.revision.number}

${bamboo.build.working.directory}

I know that I can use a line similar to the following in the Script Configuration / Environment Variables box:

RESULTSDIR="${bamboo.build.working.directory}/test-reports" BUILDNUM="${bamboo.buildNumber}" etc...

I'd like to not have to include this line every time I use the script in my Bamboo plan. Is there a way to directly access them, as the above mentioned post seems to indicate?

In the Job log there is a note stating that my globals are passed in to the environment of the remote agent that is running the perl script (a Windows box, if it matters). The build-specific variables, however, are not passed in this fashion. I tried to use a build-specific variable in the "Value" field of a global, but not suprisingly, they are not interpolated. (See screen shot).

If I have to manually pass these in everytime I run the script, it's not the end of the world, but if there is something I'm overlooking, I'd love to hear about it.

Thanks!

2 answers

1 accepted

1 vote
Answer accepted
PiotrA
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.
July 1, 2012

Indeed the build-specific variables aren't passed to the script process environment (contrary to the plan/global variables, which are passed).

Would you like me to raise a feature request on the Bamboo issue tracker?

Scott Goodwin July 2, 2012

Hi Piotr, thanks for the reply. Yes, I would really appreciate it if you would submit this as a feature request!

For what it's worth, the reason we're needing this is so that our developement builds can pull the Bamboo build #, build key, etc, in order to display it in the application's about box. My script writes these varaible values into a text file which is then used to build the versions info when the MSBuild task gets kicked off.

Currently, the workaround I'm using is a little clunky. I'm basically passing all build specific variables that I need into the script via environmental variables, then parsing this list, and matching them up to the list of variables in the script that I know I need. Bleck... messy.

Thank you!

--scott

PiotrA
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.
July 2, 2012

https://jira.atlassian.com/browse/BAM-11824

Please add yourself as a watcher and vote for that issue, so it will be scheduled sooner.

regards!

1 vote
Nathan Pickett June 17, 2015

I am using environment variables in v5.8.0 (build 5865) so this must be resolved now.

I am able to get environment variables such as buildNumber from my nant scripts without passing anything.  One gotcha for nant consumers (maybe others consumers too) is that the retrieval id is with an underscore:

${environment::get-variable('bamboo_buildNumber')}

rather than what the documentation states with a period:

${environment::get-variable('bamboo.buildNumber')}

 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events