Skip to content

Instantly share code, notes, and snippets.

@dev-marc
Created April 10, 2019 10:09
Show Gist options
  • Select an option

  • Save dev-marc/2d5504f20001f39d7cc26997a28baa33 to your computer and use it in GitHub Desktop.

Select an option

Save dev-marc/2d5504f20001f39d7cc26997a28baa33 to your computer and use it in GitHub Desktop.
# Deploy a .NET Core WebJob using Azure Powershell within a Azure Devops Pipeline
$resourceGroupName = "" #the name of the resource group
$webappName = "" #the name of the webapp you would like to deploy to)
$webjobName = "" #the name of the webjob
$path = "" #path to the .zip containing the webjob
$scheduleName = "continuous" #Name of the webjob, either 'continuous' or 'triggered'
if (-not (Test-Path $path))
{
throw [System.IO.FileNotFoundException] "$($path) not found."
}
# Retrieve WebDeploy credentials for uploading a file using Kudu
$publishingProfilesXml = [xml](Get-AzureRmWebAppPublishingProfile -OutputFile test.xml -Format WebDeploy -Name $webappName -ResourceGroupName $resourceGroupName )
$publishingProfileWebDeploy = $publishingProfilesXml.FirstChild.ChildNodes[0]
$username = $publishingProfileWebDeploy.userName
$password = $publishingProfileWebDeploy.userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiBaseUrl = "https://$($webappName).scm.azurewebsites.net/api"
# Upload the deployment zip to Kudu
$files = Get-ChildItem -Path $path -Recurse
Test-Path -Path $files[0]
$authHeader = " Basic " + $base64AuthInfo
$deployUrl = "$($apiBaseUrl)/$($scheduleName)jobs/$($webjobName)"
Write-Host "Uploading " $path " to " $deployUrl
$ZipHeaders = @{
Authorization = $authHeader
"Content-Disposition" = "attachment; filename=$($files[0].Name)"
}
$response = Invoke-WebRequest -Uri $deployUrl -Headers $ZipHeaders -InFile $files[0] -ContentType "application/zip" -Method Put
Write-Host $response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment