Passer au contenu principal

 Subscribe

 

Posted on behalf of Christopher Mank (Concurrency)

 

Having a solid source control system is essential to any software development project. What many System Admins and Engineers fail to realize is that automation development is no different. Authors of scripts and automations need the same types of tools to track and manage their code as software developers do.

Just last month, the Azure Automation team announced on UserVoice the preview of source control integration. Today, this source control is available for public use. Source control automation allows you to check-in code you're writing in Azure Automation to source control (push) and sync what’s in source control to Azure Automation (pull). In this article, we’ll take a look at why source control is so important and how to set this up in your Azure Automation environment. Let’s jump in!

Why is source control important?

Source control is a vital component to anyone who is authoring scripts and runbooks today. Not only does it provide you with history tracking of who made changes and what the changes were, but it also gives you one centralized source for all your code, which can save you hours of rework and troubleshooting if something goes wrong. Additionally, it allows for easy collaboration across teams who might have specific knowledge about one piece of the automation pipeline. Automations can describe complex processes that are mission critical to the business so they should be managed just like any other deployed software. 

Source control integration is a great step in the DevOps direction. It allows you to start putting development-like disciplines around your automations and enables you to deliver solutions faster to the business.

Having this integration built directly into Azure Automation has to be one of the most exciting features of the service, and is one of the most highly requested features on UserVoice. To put it simply, if you are not using source control for your scripts and automations today, you need to be!

Source control integration in Azure Automation

Source control integration allows you to link the runbooks in your automation account to a source control repository. Here are the steps to get this setup.

Configure GitHub

  1. Browse to https://github.com/ and either create a new or login to your existing GitHub account.
    • NOTE: The source control preview currently only integrates with GitHub. There are plans to expand this to other platforms like Visual Studio Online. You can vote for your favorite source control system here
  2. On the GitHub homepage, click “Create a repository.” You can also choose an existing repository but for this walkthrough, we’ll create a new one. Configure-Step2
  3. Give the repository a name, configure any additional settings and click “Create repository.”

Configure-Step3 

 

Configure source control integration

  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, either create a new or choose an existing Automation account where you would like to configure source control.
  3. On the bottom, click “Set Up Source Control.”
  4. On the Set Up Source Control page, enter the following values for the repository configuration and click OK to create the integration.
  • Choose source: GitHub
  • Authorization: Click the ‘Authorize’ button to grant Azure Automation access to your GitHub repository and then click OK on the bottom. Once authorized, the wizard will show your GitHub username.
  • Choose repository: Select the repository created in Step #3 above.
  • Choose branch: Choose one of the available branches.  If you have never branched the code, only “master” will be available as a selection.
  • Runbook folder path: This is the folder path within the GitHub repository where the runbook source code will be stored. Only the runbooks in the folder (not sub-folders) will be synced to Azure Automation. You can configure the folder structure however you like. The format to enter your repository is “/” for the base folder or “/folderToSync.”

Configure-step4

 

  5.  Source control integration is now configured for your Automation account. 

Configure-Step5

 

NOTE: When this integration is created, Automation Source Control is added as an Authorized application to your GitHub account. You can view this information by browsing to GitHub and clicking your profile >  Settings > Applications.

Configure-Step5B

 

Runbook check-in (Push)

A runbook check-in allows you to push the changes you’ve made to an individual runbook to your source control account. Here are the steps to perform a check-in.

  1. From the automation account where you set up source control, create a new or select an existing textual runbook and select Edit.
    • NOTE: The source control preview only supports integration with Textual/PowerShell Workflow runbooks. Support for graphical runbooks and PowerShell scripts is coming soon.
  2. In the commands at the top of the authoring blade, you will now see an option for Check-in. For our walkthrough, we’ll just add a simple variable and click “Check in.” RunbookCheckin-Step2
  3. You will be prompted with the following confirmation message. Click “Yes” to proceed with the check-in.RunbookCheckin-Step3
    • NOTE: A check-in from Azure Automation will overwrite the code that currently exists in source control.
  4. The runbook “Sync-MicrosoftAzureAutomationAccountToGithubV1” will be initiated to push the changes from Azure Automation to GitHub. You can see the progress of this job by browsing back to the root of the automation account and clicking Repository Synchronization.RunbookCheckin-Step4
  5. Select the sync job to drill in and view details of the job. You can view the job output by clicking “Output” and details about the job, including errors and warnings, by clicking “Streams.”
  6. Once the sync job is complete, we can confirm the folder and runbook successfully synced to GitHub.

RunbookCheckin-Step6

 

Runbook sync (Pull)

A runbook sync allows you to pull the current runbook code found in source control to Azure Automation. Here are the steps to perform a sync.

  1. Using the runbook example from above, click the pencil icon and make a change to the runbook in GitHub. Optionally, you can interact with your source files via the filesystem by using a Git client like the GitHub for Windows client.
  2. From the automation account where you set up source control, click Repository Synchronization à Sync. You will be prompted with the following confirmation message. Click “Yes” to proceed with the sync. RunbookSync-Step2
    • NOTE: A sync from source control will force overwrite the code that currently exists in Azure Automation for ALL runbooks that are currently in source control. As opposed to a check-in that just pushes changes for one runbook, a sync will pull the changes for ALL runbooks in source control, overwrite what’s existing, and change the authoring status to Draft (In edit) for the Azure Automation account you are using.
  3. The runbook “Sync-MicrosoftAzureAutomationAccountToGithubV1” will be initiated to pull the changes from GitHub to Azure Automation. You can see the progress of this job by browsing back to the root of the Automation account and clicking Repository Synchronization.
  4. In Azure Automation, browse back to the runbook example we’ve been using and confirm the changes from GitHub have been applied to the runbook.
    1. RunbookSync-Step4

 

Submit your feedback

Source control automation has just been released for public use and the Azure Automation team is excited to get your feedback on it. So, take it for a drive and let them know what you think by submitting your feedback on UserVoice. 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.

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation