Access Artifact BuildNumber in Azure DevOps Release Pipeline

Raymond Raymond event 2019-12-01 visibility 7,404
more_vert
Access Artifact BuildNumber in Azure DevOps Release Pipeline

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. 

20191201112044-buildnumber.PNG

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. 

2021051554626-image.png


Check the application settings in Azure App Service

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

20191201113641-buildnumber-azure-app-settings.PNG

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:

20191201114301-all-environment-variables.PNG

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts