0

so I've set up a build/deployment in VSO where I want to stop the website and web jobs before deployment (because otherwise files are locked). The powershell script essentially contains:

Stop-AzureWebsite -Name $website # this works, website is stopped after

$jobs = Get-AzureWebsiteJob -Name $website # this works, contains a list of the jobs

Stop-AzureWebsiteJob -Name $website -JobName $job -PassThru

This last line fails, using the names returned from the preceding call I get an unhelpful "Not Found". It's not an account / subscription thing as the preceding lines work happily, does anyone have any ideas?

Thanks in advance

James
  • 81
  • 6

2 Answers2

1

The solution is Remove-AzureWebsiteJob.

Regarding Stop-AzureWebsiteJob command, Starting and stopping Web Jobs is an operation that is only valid on continuous Web Jobs.

Based on the debug log (add -Debug to the command), it is trying to stop a continuous job https://[sitename].scm.azurewebsites.net/api/jobs/continuous/[jobname]/stop.

Regarding your requirement, you can try to stop the job through Kudu API.

There is the sample for using Azure App Service Kudu REST API that you can refer to: Samples for using the Azure App Service Kudu REST API to programmatically manage files in your site

Related thread: Azure Stop a Triggered Web Job

Community
  • 1
  • 1
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • Thanks, I used that, combined with Remove-AzureWebsiteJob solved my problem (which was file locks screwing up a deployment). Much abliged – James Feb 14 '17 at 08:38
  • Cool, this is the ticket, also *obliged ;) – James Feb 19 '17 at 20:13
-1

Here is a simple command:

Invoke-AzResourceAction -ResourceGroupName <RG-NAME> -ResourceType Microsoft.Web/sites/continuouswebjobs -ResourceName <APP-SERVICE/WebJobName> -Action stop -ApiVersion 2018-02-01 -Force
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77