Azure DevOps Automation

3 minute read

A couple of weeks ago the rename / rebranding of Visual Studio Team Services to Azure DevOps was announced. The rebranding is a great step forward into positioning the product even better and have more value for example for open source projects.

The service know exists out of five services that can be used independent of each other as long as you have an Azure DevOps Project.

  • Azure Pipelines: CI/CD that works with any language, platform, and cloud.
  • Azure Boards: Work tracking with Kanban boards.
  • Azure Artifacts: Public or private package repository
  • Azure Repos: Private / public Git repos
  • Azure Test Plans: Testing solution.

The above services can be specific for each project. All projects have the options to turn off a specific services. So if you for example are using Git you can start using Azure DevOps for the Builds and Release pipelines.

Azure DevOps Project

 

When using Azure DevOps a lot and also having to set up and administrate multiple environments automation comes in handy. How can we automate things around Azure DevOps?

ARM

For almost every service in Azure ARM (Azure Resource Manager) templates can be used this is no different for Azure DevOps.

Azure DevOps Organization

{
   "type": "Microsoft.VisualStudio/account",
   "name": "[parameters('accountName')]",
   "apiVersion": "2014-02-26",
   "location": "[parameters('location')]",
   "tags": {},
   "scale": null,
   "properties": {
    "operationType": "Create",
    "accountName": "[parameters('accountName')]"
  },  
  "dependsOn": []
}

Azure DevOps Project

{
  "name": "[concat(parameters('accountName'), '/', parameters('projectName'))]",
  "type": "Microsoft.VisualStudio/account/project",
  "location": "[parameters('location')]",
  "apiVersion": "2014-02-26",
  "properties": {
    "ProcessTemplateId": "[parameters('processTemplateId')]",
    "VersionControlOption": "[parameters('versionControlOption')]"
  }
}

Azure DevOps

Combining the two resources adds the ability to create an organization and project from one template.

Azure DevOps Organization and Project

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "accountName": {
      "type": "string",
      "metadata": {
        "description": "The name of the Visual Studio Team Services account, if it doesn't exist it will be created."
      }
    },
    "projectName": {
      "type": "string",
      "metadata": {
        "description": "The name of the Visual Studio Team Services project."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "processTemplateId": {
      "type": "string",
      "defaultValue": "6B724908-EF14-45CF-84F8-768B5384DA45",
      "allowedValues": [
        "6B724908-EF14-45CF-84F8-768B5384DA45",
        "ADCC42AB-9882-485E-A3ED-7678F01F66BC",
        "27450541-8E31-4150-9947-DC59F998FC01"
      ],
      "metadata": {
        "description": "Scrum: 6B724908-EF14-45CF-84F8-768B5384DA45 / Agile: ADCC42AB-9882-485E-A3ED-7678F01F66BC / CMMI: 27450541-8E31-4150-9947-DC59F998FC01"
      }
    },
    "versionControlOption": {
      "type": "string",
      "defaultValue": "Git",
      "allowedValues": [
        "Git",
        "Tfvc"
      ],
      "metadata": {
        "description": "The version control of the Visual Studio Team Services project's source code: Git or Tfvc."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.VisualStudio/account",
      "name": "[parameters('accountName')]",
      "apiVersion": "2014-02-26",
      "location": "[parameters('location')]",
      "tags": {},
      "scale": null,
      "properties": {
        "operationType": "Create",
        "accountName": "[parameters('accountName')]"
      },
      "dependsOn": [],
      "resources": [
        {
          "name": "[concat(parameters('accountName'), '/', parameters('projectName'))]",
          "type": "Microsoft.VisualStudio/account/project",
          "location": "[parameters('location')]",
          "apiVersion": "2014-02-26",
          "properties": {
            "ProcessTemplateId": "[parameters('processTemplateId')]",
            "VersionControlOption": "[parameters('versionControlOption')]"
          }
        }
      ]

    }
  ]
}

With the below PowerShell script its quick and easy to deploy these own resources.

New-AzureRmResourceGroupDeployment -ResourceGroupName [ResourceGroup Name] -TemplateFile [Template Path] -accountName [Organization name] -location [Location] -projectName [Project name] -versionControlOption Git -processTemplateId "6B724908-EF14-45CF-84F8-768B5384DA45"

Together with the Rest API you can complete the whole process.

Leave a comments if you would like to see more articles on Azure DevOps automation.