By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
access_time 13 days ago comment 0 languageEnglish

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. 

2019-12-01T11:16:31.9073238Z ##[section]Starting: Azure App Service Deploy: kontext
2019-12-01T11:16:31.9280133Z ==============================================================================
2019-12-01T11:16:31.9280240Z Task         : Azure App Service deploy
2019-12-01T11:16:31.9280327Z Description  : Deploy to Azure App Service a web, mobile, or API app using Docker, Java, .NET, .NET Core, Node.js, PHP, Python, or Ruby
2019-12-01T11:16:31.9280408Z Version      : 4.157.4
2019-12-01T11:16:31.9280454Z Author       : Microsoft Corporation
2019-12-01T11:16:31.9280535Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment
2019-12-01T11:16:31.9280606Z ==============================================================================
2019-12-01T11:16:32.6839383Z Got service connection details for Azure App Service:'kontext'
2019-12-01T11:16:33.9921958Z Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"}
2019-12-01T11:16:34.5066167Z Updated App Service Application settings and Kudu Application settings.
2019-12-01T11:16:42.2346930Z Package deployment using ZIP Deploy initiated.
2019-12-01T11:16:47.2178269Z Successfully deployed web package to App Service.
2019-12-01T11:16:47.2181086Z Updating App Service Application settings. Data: {"KONTEXT_BUILD_NUMBER":"20191201.2"}
2019-12-01T11:16:59.4388373Z Updated App Service Application settings and Kudu Application settings.
2019-12-01T11:17:00.0648701Z App Service Application URL: https://kontext.azurewebsites.net
2019-12-01T11:17:00.0730976Z ##[section]Finishing: Azure App Service Deploy: kontext

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 at 13 days ago

Please log in or register to comment. account_circle Log in person_add Register
comment Comments (0)
No comments yet.
account_circle Raymond

Data analytics with Microsoft Azure cloud platform.

open_in_new View

local_offer Tags


info License/Terms