0
votes

We have a webjob that performs certain initialization tasks post deployment. We are deploying to an AppService in Azure and this is all working well including the deployment of the webjob.

I m currently able to login to the Azure portal and execute/trigger the webJob manually which is a work around but creates a manual step in the deployment.

Does anyone know how I can use CLI or similar to trigger the run from within the VSO release scripts.

2
Please refer to: How to Ask, as you did not show a minimal reproducible example. You also didn't even bother to complete the 2-minute site tour before asking.T-Heron
what type of webjob are you using ?Thomas
Do you success to trigger web job with my way?starian chen-MSFT

2 Answers

0
votes

You can trigger WebJob through REST API (Kudu).

    param(
[Parameter(Mandatory=$true)]
[string]$websiteName,
[Parameter(Mandatory=$true)]
[string]$webjobName
)

$website = Get-AzureWebsite $websiteName
$publishingUsername = $website.PublishingUsername
$publishingPassword = $website.PublishingPassword
$base64AuthInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingUsername, $publishingPassword)))

write-host Attempting to trigger backup job;
Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://$websiteName.scm.azurewebsites.net/api/jobs/triggered/$webjobName/run -Method Post -ContentType application/json

#wait for webjob to complete - you may have a nicer way to know the webjob has completed
Start-Sleep -Seconds 5

More information, you can refer to this article: How to remotely trigger an Azure web job

Steps to run PowerShell during the build/release

  1. Add Azure PowerShell step/task to build/release definition

  2. Select Azure Classic

  3. Select Subscription

  4. Select PowerShell Script file path

  5. Specify arguments

enter image description here

0
votes

If you are using VSTS Build & Release then you can use Service Hooks. There are quite a few VSTS events that can trigger a Web Hook call. The Url to run your web job can be had from the portal by clicking on your WebJob->Properties and you would use Basic Auth with the deployment credentials from the properties page.

enter image description here