• <1 minute

Scheduling Azure Automation Runbooks with Azure Scheduler

Learn how to build more advanced schedules for you Azure Automation runbooks using the Azure Scheduler.

Having the ability to schedule a runbook is a key component to any IT organization’s automation strategy.  Azure Automation allows you to schedule a runbook to either run one time or reoccurring every specified number of hours or days.  While this functionality is great, still others require more advanced features like being able to schedule a reoccurring runbook down to the minute.

Earlier this year, Eamon posted a very similar blog to this one on how to schedule Azure Automation runbooks using Azure Scheduler.  Based on some of the comments received and the introduction of Webhooks, this process just got a whole lot easier.  Let’s take a look!

Scheduling an Automation Runbook with Azure Scheduler

At a high-level, this process only contains two principle steps.  First, create a webhook for the runbook you wish to schedule.  Second, create an Azure Scheduler job to execute the webhook at the desired time.  Here are the steps to get this schedule set up.

Create an Automation Webhook

  1. Browse to https://portal.azure.com and login to your organization’s Azure subscription.  From here, click on Browse All –> Automation Accounts.
  2. On the Automation Accounts blade, choose the account and runbook you wish to schedule.
  3. From your runbook, click Webhooks –> Add Webhook –> Create new webhook.  Give it a name and click Create.

    NOTE:  Make sure you save the URL, because once you click Create, there is no way to retrieve it again.

    Scheduling Azure Automation Runbooks with Azure Scheduler

  4. Create an Azure Scheduler Job

    1. As of the writing of this post, the Azure Scheduler is not yet available in the new Azure portal.  To access this service in the existing portal, browse to https://manage.windowsazure.com and login to your organization’s Azure subscription.  On the left-side navigation, click on Scheduler.
    2. In the bottom drawer, click New –> App Services –> Scheduler –> Custom Create.Scheduling Azure Automation Runbooks with Azure Scheduler
    3. This will open the Create Job wizard.  On the Job Collection page, enter the following values for the job collection and click the next arrow.

      Subscription:  Select one of your available subscriptions
      Region:  Select one of the available regions
      Job Collection:  Select an existing collection or create a new one
      New Job Collection Name:  If you chose to create a new collection, enter a unique name to identify the job collection

      NOTE:  Collections are scoped per subscription and region.  This means an existing collection will not be an available selection unless you select the exact same subscription and region of that existing collection.

      Scheduling Azure Automation Runbooks with Azure Scheduler

    4. On the Job Action page, enter the following values for the job schedule and click the next arrow.

      Name:  Enter a unique name to identify the job schedule
      Action Type:  HTTPS
      Method:  POST
      URI:  Enter the webhook URL created in Step #3 above
      Body:  Since the runbook is executed via a webhook, you can enter any sort of data you wish to pass to the runbook at execution time.  This data can be formatted however you choose, such as string, JSON, XML, etc.  Please refer to the Azure Automation Webhooks documentation for more information.

      Scheduling Azure Automation Runbooks with Azure Scheduler

      NOTE:  The Create Job wizard does not provide an option to configure the headers of the request, however when you select the POST method, the wizard will automatically add the following header.  Once the job schedule is created, you can browse to the properties of the job and configure additional headers if needed.

      Scheduling Azure Automation Runbooks with Azure Scheduler

    5. On the Define a Schedule page, configure the schedule based on your individual needs.  In the sample below, the schedule is set to execute every 5 minutes until the end of July.  When you’ve configured your desired schedule, click the checkmark to create the job schedule.

      Scheduling Azure Automation Runbooks with Azure Scheduler

    6. The runbook is now scheduled to run at the time you configured.  To view the history of any given job schedule, simply click on the History tab of the collection and view the results of the job.
    7. Scheduling Azure Automation Runbooks with Azure Scheduler

    And there you have it!  Using the combination of Azure Automation webhooks and the Azure Scheduler, you can now easily build schedules around your runbook automations.  Well done!

    Just getting started with Azure Automation?  Learn about the service here, and follow Azure Automation on Twitter.

    This guest blog post was contributed by Christopher Mank of Concurrency, Inc. Have an interesting idea for a blog post about Azure Automation that you’d like to feature on the Azure blog? Please contact Joe Levy on Twitter.