Nov 12, 2020

Azure Webjobs deployment using Azure Release Pipeline

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 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:

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"
Interested in hearing more?

Lets connect.

Thoughts, stories and ideas.

June 11, 2021
Using Bicep and Azure DevOps multi stage pipeline to deploy a Function App

Treating your infrastructure as code is becoming more and more necessary these days. Writing these instructions becoming challenging too. In Azure we use ARM templates to define the resources and associate them with a deployment pipeline. But ARM templates are quite complicated and they are not everybody’s cup of tea.

learn more
March 8, 2021
Guide to choosing an Compute option in Azure Machine Learning service

Azure MachineLearning Service provides four main compute options each with a specific purpose attached to it. In this post we will go through each of those and see where we can occupy them in your ML experiments.

learn more
July 6, 2020
Building Machine Learning Pipelines without Coding

In the era of Industry 4.0 where data and predictive analytics players the major role, developing machine learning pipelines have become an essential in intelligent application development.

learn more