Azure DevOps CLI
Tags: azure, devops, cli
Published: 2022-01-13 07:52:19

In my quest for incorporating automation into repetitive tasks and reducing my interaction with **Azure** services from a **GUI** perspective, using the command line has slowly become second nature. 



As the primary custodian for customer onboarding onto the various platforms and tooling that we use as an Azure Expert MSP, I often have to create a **Project** in **Azure DevOps** and create **Azure Pipelines** along with **service connections** that are used for automation, it dawned on me that I had yet to interact with Azure DevOps using the CLI.

In this blog post I'll show you how to create a **Project** as well as a  **service connection** using the **Azure DevOps CLI extension**.

Microsoft has a [Getting started with Azure DevOps CLI tutorial](https://docs.microsoft.com/en-us/azure/devops/cli/?view=azure-devops)


# ***Requirements*** #

<br>

•[Azure DevOps Organization](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/create-organization?view=azure-devops)
•[Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
•[PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.1)
•Azure DevOps extension for Azure CLI
•[Homebrew package manager (macOS)](https://brew.sh) 
•[Existing Azure AD Application](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal )


# ***Creating a Project*** #

<br>

A **Project** in **Azure DevOps** can be thought of as a repository for source code, you can store **ARM templates**, **PowerShell** scripts, **Terraform** templates, **YAML** configuration files etc.

The below **PowerShell** snippet includes variables that are used in the command to create the **Project**, I have omitted optional parameters and kept it simple.

{% gist https://gist.github.com/AdrianM10/4be53593fe938bd4d8ee26654a2c4396 %}


Once you have run the **PowerShell** commands, you'll be prompted to login via the web browser, after returning to the **PowerShell** session you'll be greeted by an output indicating that the project has been created.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lkvdtt7tep5g8jl8qxr.png)


If you navigate towards the **Azure DevOps** portal you'll notice a newly created project like the below screenshot.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5ho1dqd9zli6t925okp.png)


# ***Creating a Service Connection*** #




> Service connections enable you to connect to external and remote services to execute tasks in a job. For example, you may need to connect to your Microsoft Azure subscription, to a different build server or file server, to an online continuous integration environment, or to services you install on remote computers.

> 
It's possible to define service connections in Azure Pipelines that are available for use in all your tasks. For example, you can create a service connection for your Azure subscription and use this service connection name in an Azure Web Site Deployment task in a release pipeline.


I have a pre created application that I granted contributor access on my subscription that I will use in this step, you'll need the **Application ID** and **Client Secret**.

The below **PowerShell** script requires a few variables that will be used in the command to create the **service connection**. 



{% gist https://gist.github.com/AdrianM10/ab55be58be81ea49810569932627ad5d %}





![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnr9o5xveafjakuwaahq.png)





![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9f8otjh6z9st37jeq4bj.png)



That concludes this post. In an upcoming blog post I'll go through the process of creating a **Pipeline** using the **Azure DevOps CLI**.