Access Artifact BuildNumber in Azure DevOps Release Pipeline
access_time 2 years ago languageEnglish
more_vert

Access Artifact BuildNumber in Azure DevOps Release Pipeline

visibility 2,127 comment 0

It might be useful to push artifact or build variables to your Azure websites environment variables in Release pipelines. 

In this article, I'm going to show you how to add build number in Build pipeline to your Azure website when publishing using Release pipeline in Azure DevOps. For this website, the build number is also shown in page footer for reference. 

Available variables

Refer to the following link to find out the complete list of available environment variables that you can use in Release pipelines.

https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch

For build number, we will use this particular variable:

Release.Artifacts.{alias}.BuildNumber

The build number or the commit identifier.

Azure pipelines example: 20170112.1

Jenkins/TeamCity example: 20170112.1

TFVC example: Changeset 3

Git example: 38629c964

GitHub example: 38629c964

Use variable

In Azure App Service Deploy task in my release job, update App settings in Application and Configuration Settings section to add the following value:

-KONTEXT_BUILD_NUMBER $(RELEASE.ARTIFACTS.Starlink-ASP.NET Core-CI.BUILDNUMBER)

This step will add an environment variable named KONTEXT_BUILD_NUMBER to my ASP.NET Core application settings when doing the deployment.

Please note 'Starlink-ASP.NET Core-CI' is the artifact alias for my website build artifact. You need to replace it accordingly to your own artifact alias. 

Run the release pipeline

And then you can run the release pipeline. In the output logs, you can see the application settings is added. 



Check the application settings in Azure App Service

In Azure portal, you can also find the new settings in Settings > Configurations > Application Settings

Summary

Build number is just one of the artifact variables that you can use in release pipelines and you can use any other available variables in your Release pipelines. You can also configure this in pipeline yml file instead of using the Classic UI.

If you want to use the environment variables in PowerShell, the naming will be slightly different. For example, the build number environment name for my artifact is:

RELEASE_ARTIFACTS_STARLINK-ASP_NET_CORE-CI_BUILDNUMBER

To save your time, you can find all the available environment variable names in Initialize Job step in your release pipeline as the following screenshot shows:


info Last modified by Raymond 2 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 3067
thumb_up 1
access_time 3 years ago
Azure SQL Database Automated Backup Strategy
visibility 1163
thumb_up 0
access_time 2 years ago
visibility 1163
thumb_up 0
access_time 2 years ago