【问题标题】:Trigger an initialising webjob on VSO Release在 VSO 发布时触发初始化网络作业
【发布时间】:2016-12-22 13:34:53
【问题描述】:

我们有一个在部署后执行某些初始化任务的网络作业。我们正在部署到 Azure 中的 AppService,这一切都运行良好,包括网络作业的部署。

我目前能够登录到 Azure 门户并手动执行/触发 webJob,这是一种解决方法,但会在部署中创建一个手动步骤。

有谁知道我如何使用 CLI 或类似工具从 VSO 发布脚本中触发运行。

【问题讨论】:

  • 请参考:How to Ask,因为您没有显示minimal reproducible example。在询问之前,您甚至都懒得完成 2 分钟的实地考察。
  • 您使用的是什么类型的网络作业?
  • 你用我的方式触发web作业成功了吗?

标签: azure azure-devops azure-webjobs


【解决方案1】:

您可以通过 REST API (Kudu) 触发 WebJob。

    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

更多信息,可以参考这篇文章:How to remotely trigger an Azure web job

在构建/发布期间运行 PowerShell 的步骤

  1. 将 Azure PowerShell 步骤/任务添加到构建/发布定义

  2. 选择 Azure 经典

  3. 选择订阅

  4. 选择 PowerShell 脚本文件路径

  5. 指定参数

【讨论】:

    【解决方案2】:

    如果您使用的是 VSTS Build & Release,那么您可以使用 Service Hooks。有很多 VSTS 事件可以触发 Web Hook 调用。可以通过单击您的 WebJob->Properties 从门户获取运行 Web 作业的 URL,您可以使用 Basic Auth 和属性页面中的部署凭据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多