DEV Community

Cover image for Azure DevOps CLI
Adrian Mudzwiti
Adrian Mudzwiti

Posted on • Originally published at adrianthegreat.com

Azure DevOps CLI

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

Requirements

Azure DevOps Organization
Azure CLI
PowerShell
•Azure DevOps extension for Azure CLI
Homebrew package manager (macOS)
Existing Azure AD Application

Creating a Project

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.

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.

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

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.

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

Top comments (0)