0

Azure DevOps Automation

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.

Related Posts

Building and Deploying Azure DevOps extensions with Azure Pipelines Azure DevOps extensions can be build and deployed by using Azure Pipelines. In the Azure DevOps marketplace there is a extension available that will h...
Version number counter for Azure DevOps This week I released a new extension for Azure Pipelines called Version number counter. With this extension you add the ability to auto increment a ve...
The added value of Azure DevOps for your organization Two weeks ago Microsoft announced Azure DevOps. Azure DevOps is a name change and rebranding of the product Visual Studio Team Services (VSTS). The Az...
AKS (Kubernetes) and no connection could be made because the target machine acti... A client of my had an error while connecting to different resources within their Kubernetes cluster in Azure (AKS). Kubectl error On the kubectl com...
Kubernetes (AKS) attached to Azure Storage (Files) Kubernetes (AKS) can be used for many situations. For a client we needed to make files available trough a Kubernetes Pod. The files needed to be share...
Resource Group deployment via ARM templates When deploying an Azure Resource Manager (ARM) template you have to create a resource group within Azure. To deploy a template via script your script ...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.