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.
- 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.
- 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.
- Give the repository a name, configure any additional settings and click "Create repository."
Configure source control integration
- Browse to https://portal.azure.com and login to your organization’s Azure subscription. From here, click on Browse All > Automation Accounts.
- On the Automation Accounts blade, either create a new or choose an existing Automation account where you would like to configure source control.
- On the bottom, click "Set Up Source Control."
- 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.”
5. Source control integration is now configured for your Automation account.
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.
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.
- 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.
- 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."
- You will be prompted with the following confirmation message. Click “Yes” to proceed with the check-in.
- NOTE: A check-in from Azure Automation will overwrite the code that currently exists in source control.
- 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.
- 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."
- Once the sync job is complete, we can confirm the folder and runbook successfully synced to GitHub.
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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.