Working with Azure DevOps using Azure DevOps CLI
Posted by: Saumilkumar Shah ,
on 3/2/2020,
in
Category DevOps
Abstract: This tutorial demonstrates how to create Azure DevOps repos, boards, pipelines, artifacts etc. using Azure DevOps Command Line Interface extension.
The Azure DevOps extension for Azure Command Line Interface (CLI) provides users with the flexibility to add Pipelines, Boards, Repos, Artifacts and DevOps commands. Its predecessor, VSTS CLI has been deprecated and hence will no longer be receiving new updates.
Azure DevOps from the command line allows us to work in a streamlined task/command-oriented manner without having to worry about the GUI flows, thereby providing us a faster and flexible interaction. Also, the usage of Azure DevOps CLI can be extended for automating a series of steps/tasks, into one script.
Prerequisites:
(1) Install the Azure CLI.
(2) Add the Azure DevOps Extension
(3) Run the az login command to authenticate user.
For usage and help content for any command, pass in the -h parameter, for example:
$ az devops -h
Group
az devops : Manage Azure DevOps organization level operations.
Related Groups
az pipelines: Manage Azure Pipelines
az boards: Manage Azure Boards
az repos: Manage Azure Repos
az artifacts: Manage Azure Artifacts.
Subgroups:
admin : Manage administration operations.
extension : Manage extensions.
project : Manage team projects.
security : Manage security related operations.
service-endpoint : Manage service endpoints/service connections.
team : Manage teams.
user : Manage users.
wiki : Manage wikis.
Commands:
configure : Configure the Azure DevOps CLI or view your configuration.
feedback : Displays information on how to provide feedback to the Azure DevOps CLI team.
invoke : This command will invoke request for any DevOps area and resource. Please use
only json output as the response of this command is not fixed. Helpful docs -
https://docs.microsoft.com/en-us/rest/api/azure/devops/.
login : Set the credential (PAT) to use for a particular organization.
logout : Clear the credential for all or a particular organization.
Here are some steps to create a starter pipeline using command line:
Step 1: Install Azure CLI. The minimum requirement is v2.0.69, which can be verified with az --version command.
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
Step 2: Add Azure DevOps Extension
az extension add --name azure-devops
--name:
Extension Name
Step 3: Confirm whether the extension is installed or not using the following command:
az extension list or az extension show --name azure-devops
--name:
Extension Name
Step 4: Sign into your Azure DevOps Account using the following command:
az login
Step 5: Now we will configure the default project and organization:
az devops configure --defaults organization=https://dev.azure.com/{{OrganizationName}} project={{ProjectName}}
--defaults -d
Space separated 'name=value' pairs for common arguments defaults, e.g. '--defaults project=my-project-name organization=https://dev.azure.com/organizationName arg=value'. Use '' to clear the defaults, e.g. --defaults project=''.
Step 6: As the next step, create a repo using the following command:
az repos create --name "CLISample" --detect true --open --organization "https://dev.azure.com/sausha" --project "PublicData"
Required Parameters
--name
Name for the new repository.
Optional Parameters
--detect
Automatically detect organization.
accepted values: false, true
--open
Open the repository page in your web browser.
--org --organization
Azure DevOps organization URL. You can configure the default organization using az devops configure -d organization=ORG_URL. Required if not configured as default or picked up via git config. Example: https://dev.azure.com/MyOrganizationName/.
--project -p
Name or ID of the project. You can configure the default project using az devops configure -d project=NAME_OR_ID. Required if not configured as default or picked up via git config.
Step 7: Next, create a pipeline using the following command by passing the repo created in Step 6:
az pipelines create --name "MyCLISamplee" --description "Pipeline for CLI project" --repository CLISample --branch master --repository-type tfsgit
Required Parameters
--name
Name of the new pipeline.
Optional Parameters
--branch
Branch name for which the pipeline will be configured. If omitted, it will be auto-detected from local repository.
--description
Description for the new pipeline.
--repository
Repository for which the pipeline needs to be configured. Can be clone url of the git repository or name of the repository for a Azure Repos or Owner/RepoName in case of GitHub repository. If omitted it will be auto-detected from the remote url of local git repository. If name is mentioned instead of url, --repository-type argument is also required.
--repository-type
Type of repository. If omitted, it will be auto-detected from remote url of local repository. 'tfsgit' for Azure Repos, 'github' for GitHub repository.
accepted values: github, tfsgit
Once we run this command, it will prompt for further details (I have selected Starter pipeline as a demo template, but you may choose any other option as per your requirement):
(i) Select Pipeline template
(ii) Select/Modify yaml template
(iii) Commit file changes to repos
Now, we are good to go with our first CLI based repo and pipeline.
Conclusion:
In this tutorial, we explored one of the common scenarios where we want to create a starter pipeline through Azure DevOps CLI. In the same way, we can configure multiple items like boards, repos, artifacts, devops commands etc.
Resources:
Azure DevOps CLI Extension GitHub repo - https://github.com/Azure/azure-devops-cli-extension
Azure DevOps CLI documentation - https://docs.microsoft.com/azure/devops/cli/get-started?view=azure-devops?WT.mc_id=devopslab-c9-dabrady
This article was technically reviewed by Subodh Sohoni.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Saumil works with Microsoft as a Cloud Consultant. He comes with experience into Azure Services, DevOps, Solution Design, Release Management. He is passionate about cloud technologies. Follow him on twitter @
SaumilkumarShah and connect on
Linkedin.