Created
October 7, 2019 12:22
-
-
Save abhaydhar/8bf71138db2ec5e20ebbed3e4fb4de76 to your computer and use it in GitHub Desktop.
Powershell Script to deploy Dotnet and Unicorn Files to Azure App Service using Kudu Rest API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# User name from WebDeploy Publish Profile. | |
$userName = "`$" #Use backtick while assigning variable content | |
# Password from WebDeploy Publish Profile | |
$password = "password" | |
# Encode username and password to base64 string | |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password))) | |
$envName = "https://.scm.azurewebsites.net" #Replace from publish settings | |
$UnicornSrc = "C:\deploy\Unicorn\*" | |
$CodeSrc = "C:\deploy\WebSite\*" | |
$UnicornZipLocation = "C:\deploy\Unicorn\Unicorn.zip" | |
$CodeZipLocation = "C:\deploy\WebSite\Code.zip" | |
# Create Zip File with latest unicorn files | |
Compress-Archive -Path $UnicornSrc -CompressionLevel Fastest -DestinationPath $UnicornZipLocation | |
Compress-Archive -Path $CodeSrc -CompressionLevel Fastest -DestinationPath $CodeZipLocation | |
# Construct command api Body. DOS command to clean up existing deployment | |
$bodyToPOST = @{ | |
command = "del /S /F /Q .\\" | |
dir = "D:\home\site\wwwroot\App_Data\Unicorn" | |
} | |
# Splat all parameters together in $param | |
$destinationAppUrl = $envName +"/api/vfs/site/wwwroot/App_Data/Unicorn/?recursive=true" | |
$param = @{ | |
# command REST API url | |
Uri = $destinationAppUrl | |
Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)} | |
UserAgent = "powershell/1.0" | |
Method = "DELETE" | |
#Body = (ConvertTo-Json $bodyToPOST) | |
ContentType = "application/json" | |
} | |
# Invoke REST call | |
Invoke-RestMethod @param | |
$webdestinationAppUrl = $envName +"/api/zip/site/wwwroot" | |
# Splat all parameters together in $param hash table | |
$param = @{ | |
# zipdeploy api url | |
Uri = $webdestinationAppUrl | |
Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)} | |
UserAgent = "powershell/1.0" | |
Method = "PUT" | |
# Deployment Artifact Path | |
InFile = "C:\deploy\WebSite\Code.zip" | |
ContentType = "multipart/form-data" | |
} | |
# Invoke REST call | |
Invoke-RestMethod @param | |
$uniCorndestinationAppUrl = $envName +"/api/zip/site/wwwroot/App_Data/Unicorn" | |
# Splat all parameters together in $param hash table | |
$param = @{ | |
Uri= $uniCorndestinationAppUrl | |
Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)} | |
UserAgent = "powershell/1.0" | |
Method = "PUT" | |
# Deployment Artifact Path | |
InFile = "C:\deploy\Unicorn\Unicorn.zip" | |
ContentType = "multipart/form-data" | |
} | |
# Invoke REST call | |
Invoke-RestMethod @param |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment