build branch name to be passed to bash shell script

Answered

Dear Folks,

I have a Teamcity job that calls my bash shell script and I want to use the value in my Git branch, which I can see as a parameter teamcity.build.branch to be passed to my shell script

But I've tried a few combinations to access this and none of this work

"${teamcity.build.branch}" or {$build.branch} or echo `%teamcity.build.branch%` 

Does anyone know a way to do this?

Best regard

 

Ravi

3 comments
Comment actions Permalink

Hello,

TeamCity build parameters can be referenced via %parameter% syntax; for the build scripts the references will be replaced with the actual values before execution. I have just checked the below script:

echo %teamcity.build.branch%

in the shell, and this worked well for me. (You may want to omit apostrophes in the last variant you have tried for the desired effect).
Please let me know if this works for you.

0
Comment actions Permalink

First of all thanks for the response, I must be getting something wrong as it prints

%teamcity.build.branch%

The script I have, the key lines are like this (for brevity, I haven't copied it all).
Now, it calculates timestmap, sticks the timestamp to the outfile variable.
I also have a containerID as a Teamcity environment variable env.containerID
and it gets the value I pass, but can't get the build branch name. If I click the job's
parameter Tab once the Teamcity job finishes, I can actually see the value of teamcity.build.branch
filled with my Git branch name.

!/bin/bash
timestamp=$(date "+%Y%m%d%H%M%S")
outfile="tykjwt-$timestamp-$tykversion.so"
cp $outfile tykjwt.so
echo %teamcity.build.branch%
docker stop ${containerID}
0
Comment actions Permalink

Hi,

One more thing to check... The parameter %teamcity.build.branch% may only be available if there is a branch specification configured for your VCS Root. When there is a branch specification configured, %teamcity.build.branch% will be set to the logical branch name. If you're not using a branch specification, try using %teamcity.build.vcs.branch.<VCS_root_ID>% as follows:

!/bin/bash
timestamp=$(date "+%Y%m%d%H%M%S")
outfile="tykjwt-$timestamp-$tykversion.so"
cp $outfile tykjwt.so
echo %teamcity.build.vcs.branch.<VCS_root_ID>%
docker stop ${containerID}
0

Please sign in to leave a comment.