如何停止当前在Azure Pipelines上运行WebJobs?

时间:2019-12-23 17:04:19

标签: azure azure-devops azure-pipelines azure-webjobs

我正在尝试部署WebJobs的新版本。我有webjobs.yml个文件;

pool:
  vmImage: 'ubuntu-latest'

如果我尝试像下面那样停止,则收到错误消息;

- task: InvokeRESTAPI@1
  inputs:
    connectionType: 'connectedServiceNameARM'
    azureServiceConnection: '$(apiName)'
    method: 'DELETE'
    urlSuffix: 'https://$(apiName).scm.azurewebsites.net/api/triggeredwebjobs/$(apiName)-webjobs'
    waitForCompletion: 'true'

WebJobs-API documentation

Step references task InvokeRESTAPI at version 1.152.1 which is not valid for the given job target

如果我使用pool: server,按照建议,我将无法执行其他任务。

我也尝试使用STOP / START,如下所示。它会停止AppService而不是WebJobs。

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '$(apiName)'
    Action: 'Stop Azure App Service'
    WebAppName: '$(apiName)'    

我最终从Azure中得到错误:

The process cannot access the file XYZ because it is being used by another process.

那么,我如何从Azure Pipelines停止当前运行的WebJobs ,并部署新版本?

1 个答案:

答案 0 :(得分:0)

您正在使用Linux代理,首先要注意的是:Linux上的App Service尚不支持WebJobs。 document中对此进行了说明。

这里还有另外两种解决方案,您可以参考:

首先,您可以在临时插槽上设置此粘性应用程序设置:

  • WEBJOBS_STOPPED:1

将此设置设置为1可禁用运行任何作业(还将停止所有当前正在运行的作业)来源:Kudu Wikicase

第二个是您可以使用Invoke-AzureRMResourceAction命令。将Azure PowerShell任务添加到定义。来源:case1 case2

Invoke-AzureRmResourceAction -ResourceGroupName XXX -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName [web app name]/[web job name] -Action [start/stop] -ApiVersion 2015-08-01 -Force