Reputation: 4991
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'
Upvotes: 28
Views: 15864
Reputation: 632
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.
Upvotes: 30
Reputation: 10250
I don't think conditionals are possible. Ales might mean that each parameter could contain a string mashup, which could be parsed by the receiving script. For example,
%config.buildMode-1% == 'Debug|localhost'
%config.buildMode-2% == 'Release|http://servername'
%config.buildMode-3% == '*|http://stackoverflow.com'
Upvotes: 0