Skip to content

Instantly share code, notes, and snippets.

@abhaydhar
Created October 7, 2019 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhaydhar/8bf71138db2ec5e20ebbed3e4fb4de76 to your computer and use it in GitHub Desktop.
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
# 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