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,415,738
Community Members
 
Community Events
170
Community Groups

How to have dynamic variable in bamboo

Hi,

I'm trying to configure bamboo to have nightly builds. My goal is that after the build, the created artifacts are copied to another folder where all my nightly builds are stored.

The structure I am aiming for is the following:

C:/Sync/.../20140622-Project xx/<all my artifacts>

Everything is in place. I have a variable containing the date, I use the 'Artifact download' task in a Deploy part, and in the path, I put my date variable which is correctly substituted.

Except for one thing, I don't find a way to update the value of my variable. I tried via a script called at the begining of my Deploy to change it (global plan variable) "set bamboo_releaseDate=20140622" but this doesn't work.

I tried to change an environment variable, and access it in bamboo in the Artifact download ${system.bamboo_releaseDate}. It gets the system variable, but if I update it, it doesn't take the change into account. The new value is only taken if I restart the service of my bamboo.

So I have more a configuration/best practice question. What should be the way to have dynamic variable ? What do you suggest ? Can I use the task mentionned above, or should I change completely ?

Thanks for your help !

Christophe

3 answers

1 accepted

0 votes
Answer accepted

I used the solution of Shari, and it works effectively.

Thanks for your help !

Christophe

You should be able to run these commands in a step -

set TODAY=%year%%month%%day%
@echoTODAYVAR=%TODAY%>"${bamboo.pathroot}\Bamboo\xml-data\build-dir\TODAYVAR.properties"

Then run a step "Inject Bamboo Variables from file", where you reference the variable stored in the first step -

../TODAYVAR.properties

Then in a 3rd step set TODAY by doing the following -

for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%%month%%day%
@echoTODAYVAR=%TODAY%>"${bamboo.pathroot}\Bamboo\xml-data\build-dir\TODAYVAR.properties"

Then you can reference TODAY variable (say in your copy step) with the following -

%TODAY%_${bamboo.current.version}-${bamboo.buildNumber}

which would append the version of the app and the build number to the YYYYMMDD, i.e. 20140623_1.5.8_21

I am new to bamboo ... I have a build running but need to set up the date. Not sure why this isn't a standard feature of Bamboo by now (v6.6.3) ...

Anyway, the top commands look like Windows .BAT format, but it's not working for me as %year% and %month% and %day% are undefined ...

Are these just a placeholder for me to put the date in manually every time?

Please explain ... thanks.

I found a solution with Python to create the .properties file.

This is simpler than the solution listed above, as Python can set up the TODAY variable and write it to the properties file in one step:

 

#!/usr/bin/env python

import datetime
import sys

now = datetime.datetime.now()

mmddyyyy = now.strftime('%m%d%Y')

tfile = "C:/Users/Administrator/bamboo-home/xml-data/build-dir/AM-BLD-VAR/TODAYVAR.properties"

tout = open(tfile,'w')
tout.write("TODAY=%s\n" % mmddyyyy)
tout.close()
sys.exit(0)


One slight glitch I still have: the return value of the Python script is somehow always interpreted by Bamboo as -1, no matter what the actual return code.

For the moment I'm just running this step outside of Bamboo and disabling the step in the plan.

BUT! Atlassian: why not just export a DATETIME variable for us to use directly instead of all this??

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events