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

unable to employ variables created in batch script Bamboo task

Anthony Valencia March 5, 2013
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set thedate=%%c_%%a_%%b)
echo %thedate%
mkdir C:\Users\avalencia\test2\${system.thedate}_${bamboo.custom.svn.revision.number}
xcopy.exe TechServiceTool\TechServiceTool\bin\Release C:\Users\avalencia\test2\${system.thedate}_${bamboo.custom.svn.revision.number}\ /e

per build log, date evaluates correctly in the first line (set thedate=%%c_%%a_%%b), but is not usable in the lines afterward. how can I use thedate batch variable after it is correctly set in the first line. the goal is to have the date in a specific format to use to create a directory in which to put the build. i'd rather not create an msbuild or ant file just for this.

3 answers

0 votes
Gretchen
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.
December 1, 2013

I never could get system variables to work either. I use the injection plugin as a work around. Clunky but it works. And specifically it was on the date. Seems like a useful idea for an enhancement. have today's date as a bamboo variable since so many of us use dates in folder names (to hold builds for deployment etc.)

0 votes
Anthony Valencia March 5, 2013

xcopy, as it turns out, creates all intermediary directories, making the mkdir statement unneccessary. the echo statement was there just as a test. only one statement uses the variable. so, i simply made that last statement my do body rendering the batch variable useless. until somebody can figure out how to set batch variables in a script batch task, the solution to this problem is.

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (xcopy.exe TechServiceTool\TechServiceTool\bin\Release C:\Users\avalencia\test2\%%c_%%a_%%b_${bamboo.custom.svn.revision.number}\ /e)

0 votes
EddieW
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.
March 5, 2013

Have you tried just %thedate% ? Bamboo system variables are only updated at task boundaries, and not within a task.

Do you need the value in future tasks>?

Anthony Valencia March 5, 2013

yes i have tried %thedate%, and nothing gets substituted. essentially, it seems that the set command does not get executed. or, if it does, the variable is seemingly useless thereafter. i do not need the value in future tasks.

EddieW
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.
March 5, 2013

if you pull this code into a .bat file and run manually does it give the result you expect (other then svn which will be missing).

Anthony Valencia March 5, 2013

yes. i see where we're going with this. i believe the svn var evaluates w/in the task prior to functional parameterization. if not, then that will be the next barrier. i really didn't want to have to check any build-specific files into SVN which accomplish such trivial tasks. the script task, executable as a batch file should not be advertised as such if not the case.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events