Kodez | Your trusted consulting partner.
April 13, 2020

Azure WebJobs Deployment using Azure Release Pipelines

Azure DevOps Release pipelines has many built-in tasks that ease deployment of applications to Azure Platform but WebJobs deployments are not currently supported in these tasks. Fortunately, all Azure WebApps have Kudu installed; this post explains the steps to publish WebJobs using Kudu.

Azure WebJobs Deployment using Azure Release Pipelines

Azure DevOps Release pipelines has many built-in tasks that ease deployment of applications to Azure Platform but WebJobs deployments are not currently supported in these tasks. Fortunately, all Azure WebApps have Kudu installed; this post explains the steps to publish WebJobs using Kudu.

Obtain credentials for deployment by browsing to your Azure Portal’s Web App, under Deployment Center > FTP > Dashboard

The username seen on this FTP deployment dashboard has the following string format: APP_NAME\$APP_NAME. For this automated deployment process, the username is the latter part of this string $APP_NAME

The following screenshot shows a powershell task configured on Azure Release Pipelines to execute the deploy-webjob.ps1 script.

After adding this step, add the following variables:

  • KuduRootUrl
  • KuduUsername (TIPS: Surround with quotes)
  • KuduPassword (TIPS: Make this a secret by clicking the lock icon)
  • WebJobName
  • WebjobArtifact

The following gist is powershell script to be included in the build artifact:

param(
    [string]$KuduRootUrl,
    [string]$KuduUsername,
    [string]$KuduPassword,
    [string]$WebJobName,
    [string]$WebjobArtifact,
    [string]$ScheduleName = 'triggered'
)

if (-not (Test-Path $WebjobArtifact)) 
{
    throw [System.IO.FileNotFoundException] "$WebjobArtifact not found."
}

# Kudu Zip Deploy API URL
$deployUrl = "$KuduRootUrl/zip/site/wwwroot/App_Data/jobs/$ScheduleName/$WebJobName/"

# Prepare files
$files = Get-ChildItem -Path $WebjobArtifact -Recurse
Test-Path -Path $files[0]   

# Authentication Header
$usernamePasswordBase64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $KuduUsername, $KuduPassword)))
$authHeaderValue = "Basic $usernamePasswordBase64"

# Invoke Kudu Zip Deploy API to deploy the WebJob
$contentType = "multipart/form-data"
$userAgent = "powershell/1.0"
$ZipHeaders = @{
Authorization = $authHeaderValue
}

$response = Invoke-RestMethod -Uri  ([System.Uri]::new($deployUrl)) -Headers $ZipHeaders  -UserAgent $userAgent -Method PUT -InFile $files[0] -ContentType $contentType
Write-Host "Deployment Successful"
Kodez | Cloud. DevOps. AI. Mobility.