从 Javascript 代码启动 Azure WebJobs

Start an Azure WebJobs from Javascript code

是否有任何节点包或其他东西可以从 JS 启动 (运行) Azure Webjob?我是一名自动化人员,我想启动一个 Azure Webjob 来更改应用程序中的某些状态。手动我只是按“运行”,但我想使用代码开始工作。一个选项是登录 UI 并使用自动化按下 运行 按钮,但对我来说从 UI.

做这件事并不专业

我在那里看到了一些信息,在网络挂钩、用户、密码等 Webjob 属性中。也许我可以使用代码以某种方式使用这些东西来触发。

谢谢!

如果你想用node管理Azure WebJob,我们可以使用包azure-arm-website。该包提供方法 runTriggeredWebJobWithHttpOperationResponse 以 运行 触发 WebJob 和方法 startContinuousWebJobWithHttpOperationResponse 以连续 WebJob。

例如

  1. 创建服务主体
az login
az account set --subscription "SUBSCRIPTION_ID"
az ad sp create-for-rbac --role "Contributor" --scopes "/subscriptions/<subscription_id>"
  1. 代码
const {
  ApplicationTokenCredentials,
  AzureEnvironment,
} = require("ms-rest-azure");
const { WebSiteManagementClient } = require("azure-arm-website");

const clientId = "<the sp appId>";
const tenant = "<you AD tenant domain>";
const clientSecret = "<the sp password>";
const subscriptionId = "";
const creds = new ApplicationTokenCredentials(clientId, tenant, clientSecret, {
  environment: AzureEnvironment.Azure,
});

const client = new WebSiteManagementClient(creds, subscriptionId);
const rgName = "rg-webapp-demo";
const webName = "demo-200925164220";

const jobName = "test";
client.webApps
  .runTriggeredWebJobWithHttpOperationResponse(rgName, webName, jobName)
  .then((res) => {
    console.log(res.response.statusMessage);
    console.log(res.response.statusCode);
  })
  .catch((err) => {
    throw err;
  });

  client.webApps.startContinuousWebJob