Set VSO build/release number as Azure application setting - azure

I'm using Visual Studio Online as a build server. How can I set the build & release numbers as an Application Setting in the Azure deploy step of a release definition?

Assuming that you're able to get these numbers (which you should using available variables from https://www.visualstudio.com/pl-pl/docs/build/concepts/definitions/release/variables#default-variables), you can update web app's settings by using Azure PowerShell task with a script (or two) like:
param (
[string]$WebAppName,
[string]$SettingName,
[string]$SettingValue
)
$webApp = Get-AzureRmWebApp -Name $WebAppName
$appSettingsList = $webApp.SiteConfig.AppSettings
$hashList = #{}
foreach ($kvp in $appSettingsList) {
$hashList[$kvp.Name] = $kvp.Value
}
$hashList[$SettingName] = $SettingValue
Set-AzureRmWebApp -ResourceGroupName $webApp.ResourceGroup -Name $WebAppName -AppSettings $hashList
where SettingName and SettingValue are name and value of app setting you want to add/modify.
So script arguments may look like -WebAppName your-web-app -SettingName ReleaseNumber -SettingValue $(Release.ReleaseId).

Related

Azure Cloud Services Extended Support Deploy using New-AzCloudService powershell. Set swappable cloud service

Few days ago I moved my service from Azure Cloud Services classic to Cloud Services extended support. The latest doesn't have Production/Staging slots. There is a new swap mechanism that is activated if during a deploy we configured the "swappable cloud service". I can do it using Visual Studio publish magic and it works fine.
Now I want to make a deploy using powershell script. The code below just creates a new deploy without activated swap. It works fine.
New-AzCloudService -Name $stagingName `
-ResourceGroupName $resourceGroupName `
-Location $location `
-ConfigurationFile $cscfgFilePath `
-DefinitionFile $csdefFilePath `
-PackageFile $cspkgFilePath `
-StorageAccount $storageAccount `
-KeyVaultName $keyVaultName
I didn't find any samples or clues of how to add the "swappable cloud service" to the New-AzCloudService. I figured out there is such settings in
NetworkProfile.SwappableCloudService.Id but I can't understand how to set it up properly. For example, if I add:
$production= Get-AzCloudService -ResourceGroup $resourceGroupName -CloudServiceName $productionName
$production.NetworkProfile.SwappableCloudService.Id = $production.Name # just to reuse the object
$loadBalancerConfig = CreateLoadBalancerConfig
$networkProfile = #{loadBalancerConfiguration = $loadBalancerConfig; swappableCloudService = $production.NetworkProfile.SwappableCloudService }
New-AzCloudService -Name $stagingName `
...
-NetworkProfile $networkProfile `
I got the error:
New-AzCloudService : Parameter set cannot be resolved using the specified named parameters
Is it possible to set the "swappable cloud service" for New-AzCloudService? How to do it?
Is it possible to set the "swappable cloud service" after the deploy (in any way, Azure portal, API, powershell, etc.)?
I suspect the issue relates to the -NetworkProfile not being supported when -ConfigurationFile, -DefinitionFile, and -PackageFile are used.
In the documentation, -NetworkProfile is used with -PackageUrl and -Configuration instead.
I've asked Microsoft about this as I am having the same issue.
Try $production.Id instead of $production.Name. Or $production.id (I am not sure if the case is important).

Azure DevOps Variable Group not applying in Azure Function Configuration

I am trying to leverage the Variable Group functionality in Azure DevOps.
I have created the variable group within the Release pipeline and I have associated. However, when I release the code to the Function App in Azure; when I go to the Configuration settings in the Function app, the custom settings are not there.
Is there a step I am missing here on getting these to show up?
UPDATE: To fix this; I needed to write the variables. This is the step I did it.
I usually do this using a powershell task after publishing the new code. So add a new powershell task and define it as inline:
$appname = "name of your function app"
$rg = "name of resource group"
$webApp = Get-AzureRmwebApp -ResourceGroupName $rg -Name $appname
$webAppSettings = $webApp.SiteConfig.AppSettings
$hash = #{}
foreach ($setting in $webAppSettings) {
$hash[$setting.Name] = $setting.Value
}
$hash['New name'] = $("pipelineVariable")
Set-AzureRMWebAppSlot -ResourceGroupName $rg -Name $appname -AppSettings $hash -Slot production
PS: define the deployment slot as a variable too

How can i pass dynamic variables/secrets while deploying container image on Azure Webapp through Azure DevOps pipeline?

I am deploying docker image and wants to modify some of the application settings at runtime. I am using Azure DevOps for build and release of my docker image.
Build Pipeline: Able to create build image with default application settings.
Release pipeline: Wants to deploy build image with updated application settings. (wants to modify some of the variables)
Is this feasible? What can be the best approach of doing this?
You should create library variables with the values you want to set:
https://learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml
After that, you'll be able to retrieve the values by using:
$(customer)
I recommend you to store the content of the secrets into Azure Key Vault, and retrieve the secrets from there (also using library variables).
Lastly, all you need to do is get those values and set your app service settings (I do this through a powershell task):
$myResourceGroup = 'PartsUnlimitedMRP'
$mySite = 'centpartsunlimited'
$webApp = Get-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -Slot production
$appSettingList = $webApp.SiteConfig.AppSettings
$hash = #{}
ForEach ($kvp in $appSettingList) {
$hash[$kvp.Name] = $kvp.Value
}
$hash['customer'] = $(customer)
Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $hash -Slot production

How to rename existing Azure Logic App?

I have created a logic app, but now I want to rename existing logic app in Microsoft Azure portal.
I have been looking for options, but could not find one.
You cannot rename web app as far as I'm aware. You can redeploy using different name and then delete existing one.
Select the LogicApp, clone it with a new name, delete the old one.
Existing logic app cannot be renamed. we can clone the existing logic app with a new name.
However,the cloned logic app will be created in the same resource group of the existing logic app. we can change the resource group or location of the logic app once the cloning is completed, but in order to avoid any run time error we need to update the subscription/Resource group name or id in the code view.
You can't rename Logic App... however you can redeploy it in minutes using PowerShell
If you just want workflow definition then
$rg = "my-resoruce-group"
$logicAppName = "my-logic-app"
$newName = "my-new-name"
$logicApp = Get-AzLogicApp -ResourceGroupName $rg -Name $logicAppName
New-AzLogicApp `
-ResourceGroupName $rg `
-Name "New-Name" `
-Definition $logicApp.Definition `
-Location $logicApp.Location
Or export entire resource as ARM template and reploy it either via PowerShell, CLI or through portal
$rg = "my-resoruce-group"
$logicAppName = "my-logic-app"
$logicApp = Get-AzLogicApp -ResourceGroupName $rg -Name $logicAppName
Export-AzResourceGroup `
-ResourceGroupName $rg `
-Resource $logicApp.Id `
-Path "arm.json"
One cannot able to rename the logic app , you can able to clone the logic app with the option available in overview section of logic app as available in below picture and provide the new name. Once the new logic app gets created we can delete the old logic app.

Get PublishingPassword for website with PowerShell for new Azure portal

I used to use Get-AzureWebsite -Name myportal to get PublishingPassword what I can use inside Visual Studio to publish the WebApp to the cloud.
But now I was assigned with a new azure subscription that is not seen with the old azure command set (i.e. Get-AzureSubscription).
However this subscription is visible by Get-AzureRmSubscription (with "Rm" keyword). But Get-AzureRmWebApp doesn't contain PublishingPassword property.
Is there any other way to get PublishingPassword with new command set (that contains "Rm").
The cmdlet you are looking for is Get-AzureRmWebAppPublishingProfile At the time I looked for a more direct method, but didn't turn one up. It is a little bit convoluted, but it works. (it doesn't actually write anything to file, but as I recall it choked if it wasn't included)
This is what I did with it...
function Get-FTPCredentials
{
$Xml = [xml](Get-AzureRmWebAppPublishingProfile -OutputFile test.xml -Format Ftp -ResourceGroupName $AppServiceResourceGroupName -Name $AppServiceWebAppName )
$PublishProfile = $Xml.FirstChild.ChildNodes[1]
Write-Output ("FTP location is - " + $PublishProfile.publishUrl)
Write-Output ("FTP username is - " + $PublishProfile.userName)
Write-Output ("FTP password is - " + $PublishProfile.userPWD)
Write-Output ("Website URL is - " + $PublishProfile.destinationAppUrl)
}
Quick flow to get publishing password (PublishingPassword) for a website in Azure published via Visual Studio - manually by using PowerShell console:
Add-AzureRmAccount -TenantId 12343048-34cb-4322-b413-7b408837xxxx
Get-AzureRmWebAppPublishingProfile -Name myPortal -OutputFile test.xml -ResourceGroupName MyResourcesTestGroup
First command sets login to required tenant (directory) (i.e. adds your azure account to PowerShell session). Second gets the website (webapp) objects and prints publishing data including password.

Resources