How to integrate Azure automation with GitHub

Page content

In my previous post I wrote about using Azure automation to start and stop an Azure VM that is deployed using Resource manager. If you did not read that one I suggest you read it first since I will use that setup and the scripts in this post.

The azure automation has a great editor, but there is no version control in it. To solve this Microsoft added an option to integrate with GitHub and Visual Studio Online. For now only the GitHub one is available.

Why would you want version control?

So first why would want version control, have you ever deleted a script or changed it and thought after it ooh noo I needed the other version? Well that is the reason for version control and it is possible now with Azure automation. Also when you work with a team and everyone is working at these scripts you want to have some kind of central location to manage the scripts with some history.

How to do the setup

Now that we know why we want it, we can set it up, I assume you already have an Azure automation resource with some scripts in it. If you do not have this yet I advise you to read my previous post.

Besides an Azure automation resource we also need a location in GitHub to put our scripts. We need to create a repository in GitHub before we can connect this to Azure automation.

This can be done by going to https://github.com/new and create a new repository.

Now that your GitHub repository is created we can continue in the Azure Portal.

Go to your Azure automation resource that you want to bind to source control, on this blade at the bottom you have a tile called ‘Set up source control’

When you click on that tile you have the ability to setup source control, for now only GitHub is available.

Setting up takes five steps and must be configured in the order that the blade is presenting. The first one is choosing your source control and then you can use the second one for authorizing GitHub for access to your Azure automation resource

With the authorization done we can select the repository that we created earlier in the next step.

After selecting the repository we must select the branch and folder where the scripts are stored and you are done by clicking ‘OK’

Now we can use the same tile to see the synchronization status between GitHub and Azure automation, we also can trigger a manual Sync or disconnect from GitHub.

Working with version control

In the previous step we setup the connection between GitHub and Azure automation, now we are going to start working with it.

For the simplicity of this post I use only the master branch, but you can create different branches if necessary and use that.

Since we already have a script in Azure automation we can sync this with GitHub. We can trigger this by clicking the integration tile and click on ‘Sync’. This will trigger an PowerShell script that will upload the scripts to GitHub.

Edit options

Now that we have connected Azure Automation and GitHub we can create and edit our scripts with the beauty of version control. The editing can be done with the same editors as before

  • Azure automation
  • PowerShell ISE with the Azure automation PowerShell ISE add-on
  • Any editor you like with Git

In the Azure automation editor you have a button to check in your changes, this button will update and summit your code direct in the branch you configured

This button can also be used if you use PowerShell ISE, there is no automatic trigger to check in our code.

When we use any other editor with Git we have to trigger the sync ourselves from the automation home blade

Conclusion

The source control addition to Azure Automation is working good and the configuration is very easy and quickly done.

There are a few down sides for now and that are

  • Only GitHub is supported, so we need to have a private repository if we do not want our scripts to be out on the internet
  • When we use Azure automation or PowerShell ISE with the add-on we are not able to label the changes in GitHub. The Check in does not request for a comment.
  • When we use any other editor with Git we need to manually trigger a sync and publish our changes, it is not like Azure websites for instance where we can check in and the code is directly pushed from source control to the website.

Despite the down sides it is a great start of integrating source control into Azure automation.