2

I've created a build job that allows passing in a branch name as a build parameter and then runs the build to produce the output and copy the resulting artifact to another directory on the build server with the original artifact name suffixed with the branch name.

However when I pass in a branch name containing a slash in it (such as feature/someFeature) this causes problems since the %env.Branch% is substituted as is and makes the cp command think it's a directory.

Is there some way to parse this branch name (or any env / system / build parameter) variable in TeamCity and do some processing on it like for e.g. run a tr '/' '-' so that the slashes are replaced with hyphen?

TIA

source.rar
  • 8,002
  • 10
  • 50
  • 82
  • is it a windows or linux agent? can you use logical branch names to fix it https://confluence.jetbrains.com/display/TCD9/Working+with+Feature+Branches – KeepCalmAndCarryOn Dec 15 '16 at 00:16
  • This is a OSX agent. And it does not look like the logical branch name would be solution (at least from what I gathered) – source.rar Dec 17 '16 at 07:29

1 Answers1

6

You can create a custom first build step which cleanses the parameter via any available runner, e.g. using a Command Line runner with a custom script like:

echo "##teamcity[setParameter name='env.BRANCH' value='$(echo "%teamcity.build.branch%" | sed 's|/|-|g')']";

This uses a service message to set a new environment parameter BRANCH, which contains the value of %teamcity.build.branch% processed through a simple shell sed replacement. It can be used as %env.BRANCH% in subsequent build steps.

deceze
  • 510,633
  • 85
  • 743
  • 889