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 6, 2022
Migrating On-Prem VMs to Azure using Azure Migrate (Hyper-V Scenario) - Part 2

Part 2 of migrating on-prem VMs to azure using azure migrate (Hyper-V Scenario). Azure is Microsoft's cloud computing platform, which allows your firm access to tremendous compute capabilities while being extremely secure, allowing you to achieve any business goal without having to invest in expensive local equipment. 95% of Fortune 500 companies currently utilize the Azure Platform as part of their IT infrastructure.

learn more
May 25, 2022
Regulatory Compliance with Microsoft Defender for Cloud

Defender for Cloud provides a single platform for managing threats and the security posture of dynamic workloads on Azure. It gives you the tools you need to safeguard your resources, monitors your security posture, defends against cyberattacks, and makes security administration easier.

learn more
March 22, 2022
Modern Workplace & Azure Virtual Desktop (AVD)

Virtual desktop infrastructure is crucial for enabling on-demand remote resource access and taking your desktops and apps to a new level of flexibility and efficiency. With Virtual desktops setups, you can be more agile and innovative while reducing infrastructure cost, streamlining your organization operations, and providing a secure user experience.

learn more