Bamboo windows cmd batch variables

Hi!

I have a problem with running a batch file under windows Bamboo agent. Here is the batch:

set git_exe="C:\Program Files (x86)\Git\cmd\git.exe"
set build_type=%1
set git_repo=%2
if %build_type% == Release (
    for /f "delims=" %%i in ('UpdateVersion.exe -i Properties\AssemblyInfo.cs -w -r Fixed') do set version=%%i
    %git_exe% tag %version%
    %git_exe% push --tags %git_repo%
    UpdateVersion.exe -i Properties\AssemblyInfo.cs -o Properties\AssemblyInfo.cs -v Assembly -r increment
    UpdateVersion.exe -i Properties\AssemblyInfo.cs -o Properties\AssemblyInfo.cs -v File -r increment
    %git_exe% add -u
    for /f "delims=" %%j in ('UpdateVersion.exe -i Properties\AssemblyInfo.cs -w -r Fixed') do set new_version=%%j
    %git_exe% commit -m "Next development iteration [v.%new_version%]"
    %git_exe% push %git_repo% master
)

When the batch is run from the windows cmd - evertythings is fine:

[master warning: LF will be replaced by CRLF in Properties/AssemblyInfo.cs.
The file will have its original line endings in your working directory.
b1e6ce7] Next development iteration [v.1.0.0.8]
warning: LF will be replaced by CRLF in Properties/AssemblyInfo.cs.
The file will have its original line endings in your working directory.
 1 file changed, 2 insertions(+), 2 deletions(-)
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 377 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To ssh://git@git.exmaple.com:7999/project/repo.git
   a040944..b1e6ce7  master -> master

But when the batch is run from Bamboo (either inline or cmd), variables %version% and %new_version% are not substituting:

build	18-Mar-2014 18:47:37	[master a040944] Next development iteration [v.]
error	18-Mar-2014 18:47:37	warning: LF will be replaced by CRLF in Properties/AssemblyInfo.cs.
build	18-Mar-2014 18:47:37	 1 file changed, 2 insertions(+), 2 deletions(-)
error	18-Mar-2014 18:47:37	The file will have its original line endings in your working directory.
error	18-Mar-2014 18:47:37	warning: LF will be replaced by CRLF in Properties/AssemblyInfo.cs.
error	18-Mar-2014 18:47:37	The file will have its original line endings in your working directory.
error	18-Mar-2014 18:47:37	To ssh://git@git.exmaple.com:7999/project/repo.git
error	18-Mar-2014 18:47:37	   ecec679..a040944  master -> master

Please, advise!

1 answer

1 accepted

Found the problem and solution. It seems than while executing from Bamboo, any variable that is set in FOR loop stays in loop and is not visible from outside.

So - the solution is to move %git_exe% tag %version% and %git_exe% commit -m "Next development iteration [v.%new_version%]" to loop.

Possibly, initiating variables before loop will help, though didn't test that.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,819 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you