I have a Build and Release pipelines setup for a project and I want to be able to get the Build Number that was used for the Release into the running application.
I've seen a number of explainations of how to use the Release.Artifacts.{alias}.BuildNumber variable for things like the artifact output, however I haven't been able to find how to use this to directly update the App Settings for the App Service. I've found a few Tasks available to use in the Release process that allow changing of App Settings, but none of them supported using variables from the build process (just allow setting of static values)
I want this to be set at the App Service level so that the website and all the webjobs are able to access the variable (rather than having to update several app.config files).
Can anyone point me in the right direction for this?
Delay in updating this, however this is the Powershell based solution I arrived at and this has been working well so far.
Added this as a Powershell script within the solution and updated the Build process to copy this artifact
param (
$myResourceGroup,
$mySite,
$mySlot,
$buildNo
)
$webApp = Get-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -Slot $mySlot
$appSettingList = $webApp.SiteConfig.AppSettings
$hash = @{}
ForEach ($kvp in $appSettingList) {
$hash[$kvp.Name] = $kvp.Value
}
$hash['BuildNumber'] = $buildNo
Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $hash -Slot $mySlot
This takes the parameters provided and retreives the current App Settings from the slot and adds/updates the BuildNumber setting to the $buildNo parameter that is received.
During the Release process, I added in an Azure Powershell task to call this script and then set the "Script Argurements" field to the following
-myResourceGroup "WebResourceGroup" -mySite "myexamplservice" -mySlot "staging" -buildNo $(Build.BuildNumber)
Now I can read the "BuildNumber" app setting within my website and get the deployed build number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With