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

Accepted Answer
0 votes

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
Community showcase
Published 6 hours ago in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

48 views 0 1
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