3
votes

I have my build number format specified as :

$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

This creates build Numbers in the format of "BuildDefinitionName_2015.11.11.1"

Where revision seems to be the number of times the build has run for that day.

I would like to be able to use this value in further build steps.

For example I am creating a nuget package with the nuget packager step and am using the option "Use build number to version the package"

This creates me packages similar to this "PackageName.2015.11.11.1.nupkg"

I then want to use the nuget publisher build step to publish this, but the problem is that over time you get more than one package in the package folder and the nuget publisher step uses a pattern for matching packages to publish.

ie

  • "PackageName.2015.11.11.1.nupkg"
  • "PackageName.2015.11.11.2.nupkg"
  • "PackageName.2015.11.11.3.nupkg"

Without being explicit about the file to publish, the publisher step will publish all these files.

I don't want this, I just want it to publish the file which matches the current build number.

So I would like to be able to set the build number parts in the pattern.

ie PackageName.$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r).nupkg

But it appears that these variables do not get substituted in the search path and come through as a literal match.

It seems strange that in the nuget package step it gives you the option to create packages by build number, but then does not allow you to match this in the nuget publish build step.

2

2 Answers

3
votes

Nuget Packager step use PowerShell script to get the build number. The source code is here: https://github.com/Microsoft/vso-agent-tasks/blob/84746169f19b7c3e3f67c0efa1a546c4107055fa/Tasks/NugetPackager/NuGetPackager.ps1

If you do want to transfer the build number to Nuget Publish, you can add a PowerShell step in your build process to get the build version number. Refer to the build version related code in the Source Code for details.

And in the end of the PowerShell script, add code:

Write-Host "##vso[task.setvariable variable=bversion;]$NewVersion"

This code create a variable “bversion” with build version number filled. Then you can use variable $(bversion) in your Nuget Publish step.

0
votes

I would suggest to do a clean checkout of the source code in each build, which will solve the problem of having old package files lying around in subsequent builds.

Otherwise there's the $(build.buildnumber) variable which contains the expanded value of the build number, but as long as you have additionally the $(BuildDefinitionName) in the build number you won't be able to use it for the file name. See here for a list of available predefined variables.