0
votes

We are trying to use Azure DevOps to build our git branches and produce NuGet packages using the NuGet Pack command, we want to automatically build master and also any feature branches that are pre-release.

We have tried setting the build number format to:

$(BuildDefinitionName)_$(Date:yyyyMMdd).$(BuildID).$(Rev:.r)$(Build.SourceBranchName)

This gives us the error:

[error]Could not find version number data in the following environment variable: BUILD_BUILDNUMBER. The value of the variable should contain a substring with or are positive integers.

I set the build number format to 1.0.0-alpha which worked but in the Artifacts list it just shows as 1.0.0.

How can we use CI in Azure Devops to build master and all our feature branches, produce the NuGet packages and apply the branch name to the NuGet version so we can consume these packages in our test environment and test a feature branch in isolation?

1
why dont you setup a build trigger? why do you care about the build name?4c74356b41
Because we want a single build pipeline, don’t want to create one for each feature branch. Then we want to take the NuGet package that is packed with the feature branch in the name and deploy for testing.user351711
Happy for alternate suggestions for feature branch building, deployed with NuGet that doesn't require changing build pipelines for each new feature branch.user351711
@user351711 Did you try $(Build.DefinitionName) and $(Build.BuildId) (maybe the error is because environments syntax errors)?Shayki Abramczyk
Does the pipeline fail to start with the error you provided, or does a particular step fail? Why is NuGet tagged?zivkan

1 Answers

1
votes

How can we use CI in Azure Devops to build master and all our feature branches, produce the NuGet packages and apply the branch name to the NuGet version so we can consume these packages in our test environment and test a feature branch in isolation?

I am sorry for this late reply, I hope it will give you any help.

I am afraid we could not use the $(Build.SourceBranchName) in the build number format as nuget version. After I tried the build number in various formats, I found we could only use the number data as nuget version when using the build number as nuget version, otherwise, we will got the error like you:

"the variable should contain a substring with or are positive integers"

Then I create a branch with number data, like 9, it works fine.

So, as test, we could not apply the branch name (String) to the NuGet version when using build number as nuget version.

As workaround, I use the option Use an environment variable, then define the variable nugetversion with value $(Major).$(Minor).$(Patch)-$(Build.SourceBranchName):

enter image description here

enter image description here

enter image description here

With this workaround, we can use the branch name as the version of the nuget package, but it also has some limitations, that is, we could not use some predefined variables, like $(Rev:.r), $(BuildID), that means we unable to automatically increment the version of the nuget package.

Hope this helps.