Reputation: 45
I'm trying to set a bamboo global variable in a script contained in a batch file. Here is the batch file:
@echo off
echo Initial Date: %bamboo_releaseDate%
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
set mydate=%month%_%day%_%year%
echo %mydate%
set bamboo_releaseDate = %mydate%
echo Set up date: %bamboo_releaseDate%
And here is my output:
Initial Date: 140617
06_19_2014
Set up date: 140617
As you can see, the variable %bamboo_releaseDate% didn't change at all. Any idea if it's possible, and how can I do it?
My end goal is to use this variable in the naming of the folders containing my nightly builds (using the standard 'Artifact download' provided by Bamboo).
I have fixed the batch issue, but the updated value isn't available after the script. Any idea how to do it?
Upvotes: 2
Views: 3119
Reputation: 1918
i think there is the problem with the date parsing.
in your for loop, try to print out %%i:
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
ECHO i=%%i
...
)
What do you get?
Working with %DATE% in batch files is dangerous as the format depends on the current system/user settings
Upvotes: 0
Reputation: 70933
set bamboo_releaseDate = %mydate%
^ ^
The spaces are included in the name of the variable and in the value. So, you are assigning value to a new variable (that includes a space in its name), not to the existing one (without the space). Replace with
set "bamboo_releaseDate=%mydate%"
Now, there are no spaces not in the name of the variable nor in its value, and the quoting ensures there is no aditional ending space in the variable content.
Upvotes: 2