【问题标题】:Azure Automation Managment not able to execute run bookAzure 自动化管理无法执行运行手册
【发布时间】:2016-06-24 01:36:39
【问题描述】:

我正在使用 Azure 自动化管理 2.0.1。我无法找到 Runbook 的 Start 方法来执行 Runbook。如何使用 2.0.1 进行此操作

var client = new Microsoft.Azure.Management.Automation.AutomationManagementClient(new CertificateCloudCredentials(subscriptionId, cert));
var ct = new CancellationToken();

var content = await client.Runbooks.ListByNameAsync("MyAutomationAccountName", "MyRunbookName", ct);

var firstOrDefault = content?.Runbooks.FirstOrDefault();
if (firstOrDefault != null)
{
    var operation = client.Runbooks.Start("MyAutomationAccountName", new RunbookStartParameters(firstOrDefault.Id));
}

【问题讨论】:

    标签: azure azure-automation


    【解决方案1】:

    您需要使用automationManagementClient.Jobs.Create

    public static JobCreateResponse Create(
        this IJobOperations operations,
        string resourceGroupName,
        string automationAccount,
        JobCreateParameters parameters
    )
    

    您可以找到完整的示例here 这将是相关部分 -

    private void JobStart_Click(object sender, RoutedEventArgs e)
     {
            // Check for runbook name
            if (String.IsNullOrWhiteSpace(RunbookName.Text) || String.IsNullOrWhiteSpace(PublishState.Text)) throw new ArgumentNullException(RunbookName.Text);
    
            // Create job create parameters
            var jcparam = new JobCreateParameters
            {
                Properties = new JobCreateProperties
                {
                    Runbook = new RunbookAssociationProperty
                    {
                        // associate the runbook name
                        Name = RunbookName.Text
                    },
    
                    // pass parameters to runbook if any
                    Parameters = null
                }
            };
    
            // create runbook job. This gives back JobId
            var job = automationManagementClient.Jobs.Create(this.automationAccountName, jcparam).Job;
    
            JobGuid.Text = JobId.Text = job.Properties.JobId.ToString();
    
            Log.Text += (String.Format("\nJob Started for Runbook {0} , JobId {1}", RunbookName.Text, JobId.Text));
    }
    

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 2016-06-17
      • 2021-12-21
      • 1970-01-01
      • 2019-02-03
      • 2022-10-21
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多