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.

7 Replies to “Azure DevOps Automation”

  1. I likable the posts and offbeat format you’ve got here! I’d wish many thanks for sharing your expertise.

    1. Hi Dennis,

      Not at this point. I have a few examples already with PowerShell. Are you looking for specific functionality?

  2. Hi Maik,
    Now after using Azure DevOps for a long time, we always have to perform some repetitive tasks for different environments (ST,SIT, Replica & Prod) such as creating image, tasks and then deploy them in each environment. Is there a method to automate these task suppose if a feature or bug that is successful in one environment can be pushed to other environments automatically.

    1. Hi Iqbal,

      Yes that should be possible depending on your process. When you would like to discuss options please let me know and we will schedule something.

  3. Hi Malik,
    What authorization is needed to execute this? When I use my own Azure credentials (admin in Azure resource group and in Azure DevOps) I get this error message: “TF14045: The identity with type ‘Microsoft.IdentityModel.Claims.ClaimsIdentity’ could not be found.”
    When I use Azure AD App registration, I get error: VS403283: Could not add user ” at this time.

    1. Hi Malik,

      I think that is an issue with your authentication. The only thing that I know for sure is that you will have to use a user account.

Leave a Reply

Your email address will not be published.

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