Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipeline - Increment build number and display in web app

I have the following simple build pipeline working in Azure DevOps with releases deployed to a staging slot.

enter image description here

I would like to have a build revision/version string and that is auto-incremented. I then want to display this in my web app so I can tell which version of the software is in production.

Currently I display the version string from the .csproj file. Something like this in a

<Version>1.1.4.7</Version>

And then displayed on a web page using the following code:

Version: @typeof(Startup).Assembly.GetName().Version.ToString()

If I can update the existing version string that would be great but I'm open to changing to whatever's easiest to integrate in the CI process.

like image 229
Brad Patton Avatar asked Dec 12 '18 03:12

Brad Patton


People also ask

How do I find my build number in Azure DevOps?

Build numbers in Azure DevOps For example, Microsoft's Build Number format documentation gives an example: $(TeamProject)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:. r) will result in a version number like Fabrikam_CIBuild_main_20090805. 2 .

How do I find build number in release pipeline?

If you linked a build as release artifact, then you can use $(Build. BuildNumber) to get build number. If you have the issue, please provide the details of your release pipeline (Linked artifact, Docker push task setting, detail log).

How do I monitor Azure DevOps pipeline?

Configure continuous monitoringIn Azure DevOps, select an organization and project. On the left menu of the project page, select Pipelines > Releases. Drop down the arrow next to New and select New release pipeline. Or, if you don't have a pipeline yet, select New pipeline on the page that appears.

What are the two ways for Azure pipelines to be built?

Azure DevOps supports two forms of version control - Git and Azure Repos. Any changes you push to your version control repository will be automatically built and validated.


1 Answers

Versioning has been simplified in the .Net Core world.

Edit your csproj and modify it as follows:

<PropertyGroup>
  <Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">1.0.0.0</Version>
  <Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
</PropertyGroup>

If your file doesn’t have a version node, add the above.

The above setup will mean debugging locally will give you a version of 1.0.0.0, and in the event, you build in a non-Azure DevOps environment you will also end up with a 1.0.0.0 version. $(BUILD_BUILDNUMBER) is an environment variable set by Team Build and which will be updated at build time by VSTS or TFS.

The .Net version needs to be in the format [major].[minor].[build].[revision] with each segment being a number between 0 and 65000. You can configure the build number format in the Options tab, see here more info about the formatting. See here for helpful steps on configuring the build.

like image 67
Shayki Abramczyk Avatar answered Sep 19 '22 07:09

Shayki Abramczyk