Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity conditional parameter values

Tags:

How can I assign a runtime value to a build parameter? I set a build parameter, let's say %config.buildMode%, to a dropdown and I need to have something like an IF condition so that I can assign a different value to another parameter based on the buildmode selection.

e.g.

if %config.buildMode% == 'Debug'    %config.hostName% = 'localhost' else if %config.buildMode% == 'Release'    %config.hostName% = 'http://servername' else    %config.hostName% = 'http://stackoverflow.com' 
like image 415
Leon Tayson Avatar asked Jun 16 '13 23:06

Leon Tayson


1 Answers

Rather late to the party, but it is possible. Add an extra parameter for the value you want to be conditional (e.g. TargetServerName), but leave the value blank. Then add a powershell build step at the start of your process, and enter a script like this;

$BuildMode = "%buildMode%" $ServerName = ""  if ($BuildMode -eq "Debug") {   $ServerName = "localhost" } elseif ($BuildMode -eq "Release") {   $ServerName = "theserver" } else  { exit 1 } echo "##teamcity[setParameter name='TargetServerName' value='$ServerName']" 

The final line is the magic. By outputting that, teamcity will basically execute it, setting your TargetServerName parameter. You can then use the parameter in subsequent build steps.

like image 72
PaulMolloy Avatar answered Oct 10 '22 04:10

PaulMolloy