In this step-by-step guide, we will walk you through the process of configuring Azure DevOps as your source control for Azure Automation, The video below that covers the process start to finish on how to set up Azure DevOps for Azure Automation. We also have a guide on how to convert interactive PowerShell scripts to in unattended scripts and move them to Azure Automation
Understand the Benefits
Before you begin, it’s essential to understand the advantages of using Azure DevOps as your source control for Azure Automation. Azure DevOps offers centralized script management, version control, collaboration features, and change tracking.
1. Set Up Azure DevOps Account
Ensure you have an Azure DevOps account. If you don’t have one, creating an Azure DevOps Organization is straightforward and cost-effective, with the first 5 users being free, and a basic $5 per user license sufficing for script management. Visual Studio subscriptions also include Azure DevOps access.
- Visit the Azure Portal and search for “DevOps.”
- Create a DevOps Organization by providing a name and selecting the hosting region based on your preference.
2. Create a DevOps Project
Once you have an Azure DevOps account, create a new project. You can configure projects according to your use case, but for this example, let’s create a project named “Scripting” to hold your scripts.
- Access your Azure DevOps account.
- Create a new project, setting it up as needed.
3. Configure Your Project
Now, let’s configure your project to work with Azure Automation.
- Inside your Azure DevOps account, navigate to the “Repos” tab.
- The project will create a repository with the same name as the project, which is suitable for this example.
- To create a folder for Azure Automation syncing, you need to create a placeholder file since Git doesn’t allow empty folders. Create a placeholder file named “Placeholder.”
- Consider cloning the repository to your computer using Visual Studio Code for easier management.
4. Connect Azure Automation to Azure DevOps
Before connecting Azure Automation to Azure DevOps, configure some permissions.
- In “Project Settings,” navigate to “Security Policies” and enable 3rd party Application Access via OAuth.
- Add the managed identity from the Azure Automation Instance as a project contributor on the Azure DevOps Project. Note that this consumes a basic DevOps license.
- Ensure that the Azure Automation Managed Identity has contributor permissions on its own Azure Automation Instance.
Now, you can configure the source control in Azure Automation:
- Inside your Azure Automation account, go to the “Source Control” tab.
- Select “Add” and give the source control an intuitive name.
- Choose “Azure DevOps Git” as the source control type.
- Authenticate using your Azure DevOps account credentials.
- Select the repository and branch from the DevOps Project.
- If you’re focusing on a specific folder, specify the folder path.
- Turn on “Auto Sync” and leave “Publish Runbook” enabled.
- Click “Save” to save this configuration.
5. Move Your Scripts
Now, you can move your existing scripts into Azure DevOps:
- Use Visual Studio Code to copy your existing script from Azure Automation to a new file in the Azure DevOps Repository.
- Note: If you’re not migrating existing scripts, you can start creating and saving your scripts directly in the Azure DevOps repository.
- Commit and push your automation script to the Azure DevOps repository. This enables Git’s version control features, allowing you to track changes and revert to previous versions if needed.
6. Enable Syncing in Azure Automation
Once your scripts are in Azure DevOps, you can enable syncing in Azure Automation. Wait for the syncing process to complete.
7. Test Your Scripts
After syncing, test your scripts to ensure they work as expected. Make any necessary adjustments or updates.
You will have to add any PowerShell modules or Python packages that your scripts require in your Azure Automation account. This is crucial to prevent script failures.
Congratulations! You have successfully configured Azure DevOps as your source control for Azure Automation. This setup allows you to collaborate with your team, track changes, and maintain version control for your automation scripts.
Now, you can enjoy the benefits of centralized script management and efficient collaboration. Thank you for following this step-by-step guide, and feel free to leave any questions or comments below.