Search code examples
c#azureazure-automationazure-runbook

How to start an Azure runbook/webhook using Microsoft.Azure.Management.Automation AutomationClient in C#?


I am using the .NET SDK to build an application which will trigger Azure automation runbooks. I've tried to start the runbook using a webhook but I am unable to find the method that will start the webhook and return a job ID.

I am using the AutomationClient from the namespace:

Microsoft.Azure.Management.Automation Version: 3.8.0-preview.


Solution

  • I suggest you can use AutomationManagementClient instead. Here is an example:

        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
    

    For more details, you can refer to here.