3
votes

I'm setting up a CI script for one of our Azure web apps, and I want to use deployment slots to enable per-branch deployments of the app into our development subscription.

I'm able to create the deployment slot easily, and I've had some success configuring app settings via PowerShell.

The major hang-up at the moment is that I need to also configure the deployment options for the newly created slot. We publish our sites via local git repositories. I've tried using both PowerShell and the CLI, but I'm getting errors setting the repoUrl parameter.

I built this script modeled after an example from Microsoft. Additionally, I verified that the command syntax matches what's shown in the Azure Resource Manager.

$ResourceGroupName = "group-name"
$SubscriptionId = "guid-value-redacted"

Login-AzAccount -Subscription $SubscriptionId

# Configure environment properties

$WebAppName = "web-app-name"
$AppServicePlanName = "web-app-plan-name"
$SlotName = "branch-name"

New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -AppServicePlan $AppServicePlanName -Name $WebAppName -Slot $SlotName

$PropertiesObject = @{
    repoUrl = "https://$WebAppName-$SlotName.scm.azurewebsites.net/"
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/sourcecontrols -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force

All this works fine, up until the last command, which returns this error:

Set-AzureRmResource : {"Code":"BadRequest","Message":"The parameter https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid value.","Target":null,"Details":[{"Message":"The parameter 
https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid value."},{"Code":"BadRequest"},{"ErrorEntity":{"ExtendedCode":"51008","MessageTemplate":"The parameter {0} has an invalid 
value.","Parameters":["https://web-app-name-branch-name.scm.azurewebsites.net/"],"Code":"BadRequest","Message":"The parameter https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid 
value."}}],"Innererror":null}
At line:6 char:1
+ Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : BadRequest,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourceCmdlet

What am I doing wrong here? I know the sample is based on publishing from GitHub, but the parameter I'm providing here matches the format used by another deployment slot that I configured manually for local git deployment. It seems to me like this should work, but obviously I'm missing some important detail.

2

2 Answers

4
votes

You could use Azure Power Shell and Azure CLi to do this.

Power Shell.

# Configure environment properties
$ResourceGroupName = "shuiapp"
$WebAppName = "shuicli"
$AppServicePlanName = "myAppServicePlan"
$SlotName = "shuislot"

New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -AppServicePlan $AppServicePlanName -Name $WebAppName -Slot $SlotName

$PropertiesObject = @{
    scmType = "LocalGit";
}

Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force

Azure Cli 2.0

az webapp deployment source config-local-git --name --resource-group --slot

See this link

Hope this helps.

2
votes

It turns out the repoUrl is a derived property if you deploy from local git. To enable local git deployment, you set a different property in a different location.

Microsoft support pointed me in the direction of a different guide which I was able to follow to configure the deployment slot.

The modified version of the last couple lines looks like this:

$PropertiesObject = @{
    scmType = "LocalGit";
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force