问题
I am trying to find a way to deploy an app service update to an Azure app service from a Bamboo deployment server script task using PowerShell.
I am running into a problem with the authentication part.
Note: Credit to https://markheath.net/post/deploy-azure-webapp-kudu-zip-api for the script ideas.
Below is my PowerShell script.
$PublishingUsername = ["The value of the userName property name in the Azure PublishSettings file"]
$PublishingPassword = ["The value of the userPWD property name in the Azure PublishSettings file"]
$SlotName = ["The name of the slot. I.e. qa"]
$WebAppName = ["The name of the app service in Azure"]
$LocalPath = ["The location of zip file that holds the VS2017 Publish Output files"]
function Upload-ZipDeploy() {
$pair = "$($PublishingUsername):$($PublishingPassword)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
if ($SlotName -eq ""){
$kuduApiUrl = "https://$WebAppName.scm.azurewebsites.net/api/zipdeploy"
}
else{
$kuduApiUrl = "https://$WebAppName`-$SlotName.scm.azurewebsites.net/api/zipdeploy"
}
# use kudu deploy from zip file
Invoke-WebRequest -Uri $kuduApiUrl -Headers $Headers `
-InFile $LocalPath -ContentType "multipart/form-data" -Method Post
}
Upload-ZipDeploy
When I run this script I get
Invoke-WebRequest : Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the
credentials that you supplied.
I am using the userName and userPWD values from the *.PublishSettings file I downloaded for the app service deployment slot settings in Azure. I can import this same *.PublishSettings file in the publish wizard in VS2017 and successfully publish to that slot. I just can't seem to do it in PowerShell.
What am I missing here?
回答1:
The solution here was fairly simple. I was using the Microsoft generated username from the publishSettings file and that username started with a $. So, PowerShell was stripping the $and first characters. I prefixed the username with a back-tick and this prevented the username from being stripped. It is now working correctly.
I also added the:443 after the azurewebsites.net domain since that is the way it appears in the publishSettings file, but I am not sure it is actually needed since the url starts with https:// already.
来源:https://stackoverflow.com/questions/47895398/how-to-use-azure-kudu-zipdeploy-from-a-bamboo-deployment-server