SetParameter with Powershell

I have the following script that I'm attempting to use in order to set different build numbers for Master/Develop/Feature branches.  I spent most of yesterday attempting to set a parameter for use in updating assembly information.  The basic workflow is as follows.

  1. Build on new commits
    1. Setup build numbers and set parameter for file naming in second build config (code below is not working)
    2. Build VS2013 project
    3. Run unit tests
  2. Package and deliver
    1. Copy artifacts from above build
    2. Run Innosetup to create .exe file.


Step 1.1 looks like this:

# These are project build parameters in TeamCity
# Depending on the branch, we will use different major/minor versions
$majorMinorVersionMaster = "%system.MajorMinorVersion.Master%"
$majorMinorVersionDevelop = "%system.MajorMinorVersion.Develop%"
$patchMaster = "%system.Patch.Master%"
$patchDevelop = "%system.Patch.Develop%"


# TeamCity's auto-incrementing build counter; ensures each build is unique
$buildCounter = "%build.counter%"

# This gets the name of the current Git branch.
$branch = "%teamcity.build.branch%"

# Sometimes the branch will be a full path, e.g., 'refs/heads/master'.
# If so we'll base our logic just on the last part.
if ($branch.Contains("/"))
{
  $branch = $branch.substring($branch.lastIndexOf("/")).trim("/")
}

Write-Host "Branch: $branch"

if ($branch -eq "master")
{
$buildNumber = "${majorMinorVersionMaster}.${patchMaster}.${buildCounter}"
}
elseif ($branch -eq "develop")
{
$buildNumber = "${majorMinorVersionDevelop}.${patchDevelop}.${buildCounter}"
}
elseif ($branch -match "release-.*")
{
$specificRelease = ($branch -replace 'release-(.*)','$1')
$buildNumber = "${specificRelease}.${buildCounter}"
}
else
{
# If the branch starts with "feature-", just use the feature name
$branch = $branch.replace("feature-", "")
$buildNumber = "${majorMinorVersionDevelop}.${patchDevelop}.${buildCounter}-${branch}"
}

# this correct outputs the $buildNumber I'd like to see
Write-Host "##teamcity[buildNumber '$buildNumber']"
# this does NOT set the parameter at all
# it outputs the correct buildNumber but the parameter is not updated
Write-Output "##teamcity[setParameter name='system.FullBuildNumber' value='$buildNumber']"
Write-Host "##teamcity[setParameter name='system.FullBuildNumber' value='$buildNumber']"


I've been trying to get the setParameter functionality to work, and it doesn't seem to matter which way I write it.  It won't update the parameter for use later in the second build configuration.  The reason I'd like to use it in the second build is for naming the .exe file.

2 comments
Comment actions Permalink

"It won't update the parameter for use later in the second build configuration"

So, you're trying to set the parameter for use in a subsequent build configuration, not the current configuration?  I don't believe that can be done.  You can definitely use it in the same build, but I don't think modifications to those parameters survive the end of a build.  I know they definitely don't for environment params.

0
Comment actions Permalink

That's what I came to the conclusion for yesterday.  This is a project wide parameter, not just a build configuration parameter.  I would assume that this is possible somehow.  If not, then I'll have to come up with a workaround.  Project wide parameters should persist across all build configurations for that project.



Attachment(s):
Capture.PNG
0

Please sign in to leave a comment.