【问题标题】:How to start an Azure runbook/webhook using Microsoft.Azure.Management.Automation AutomationClient in C#?如何在 C# 中使用 Microsoft.Azure.Management.Automation AutomationClient 启动 Azure Runbook/webhook?
【发布时间】:2019-06-26 19:29:06
【问题描述】:

我正在使用 .NET SDK 构建将触发 Azure 自动化运行手册的应用程序。我尝试使用 webhook 启动 Runbook,但找不到启动 webhook 并返回作业 ID 的方法。

我正在使用命名空间中的 AutomationClient

Microsoft.Azure.Management.Automation 版本:3.8.0-预览版。

【问题讨论】:

  • 我没有尝试过,但从文档中看到 GetWithHttpMessagesAsync 返回一个具有 Job 模型的任务,您可以找到 Job ID 具有其中一个属性
  • 谢谢@Jayendran,但我认为GetWithHttpMessagesAsync 用于检索已经启动的作业。我正在寻找一种方法来启动 webhook 或 Runbook,然后返回它的 Job ID。
  • 缺少这个的doc,但是你可以尝试使用其他方法启动job并获取job id。

标签: c# azure azure-automation azure-runbook


【解决方案1】:

我建议您可以改用 AutomationManagementClient。这是一个例子:

    AutomationManagementClient client =
        new AutomationManagementClient(new CertificateCloudCredentials(subscriptionId, cert));

    // Create job create parameters
    JobCreateParameters jcParam = new JobCreateParameters
    {
        Properties = new JobCreateProperties
        {
            Runbook = new RunbookAssociationProperty
            {
                Name = runbookName
            },
            Parameters = null // optional parameters here
        }
    };

    // create runbook job. This gives back the Job
    Job job = automationManagementClient.Jobs.Create(automationAccountName, jcParam).Job;

   // then you can get the job id from the return Job object

更多详情可以参考here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2021-07-27
    • 2018-02-03
    • 2022-11-11
    • 2018-06-04
    相关资源
    最近更新 更多