Skip to content

Commit 285eb61

Browse files
author
gitstua
committed
quick post as sample azure ADO cli extension
1 parent e5c35d8 commit 285eb61

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: post
3+
published: true
4+
title: List Azure DevOps Repos
5+
date: '2021-05-17'
6+
subtitle: Example of how to interact with Azure DevOps using the Azure CLI Example
7+
---
8+
9+
## Problem
10+
How do I get all the URLs for my repos in Azure DevOps?
11+
12+
## Solution
13+
Use the [Azure DevOps CLI extension](https://docs.microsoft.com/en-us/azure/devops/cli/?view=azure-devops#:~:text=%20To%20start%20using%20the%20Azure%20DevOps%20extension,you%20set%20the%20default%20configuration%20for...%20More%20)
14+
15+
This is a sample PowerShell script
16+
17+
```
18+
param( [string]$Organization )
19+
20+
$orgUrl = "https://dev.azure.com/$Organization"
21+
22+
# Ensure signed in to Azure
23+
$AccountInfo = az account show 2>&1
24+
try {
25+
$AccountInfo = $AccountInfo | ConvertFrom-Json -ErrorAction Stop
26+
}
27+
catch {
28+
az login --allow-no-subscriptions
29+
}
30+
31+
$DevOpsExtension = az extension list --query '[?name == ''azure-devops''].name' -o tsv
32+
if ($null -eq $DevOpsExtension) {
33+
$null = az extension add --name 'azure-devops'
34+
}
35+
36+
$Projects = az devops project list --organization $orgUrl --query 'value[].name' -o tsv
37+
foreach ($Proj in $Projects) {
38+
$Repos = az repos list --organization $orgUrl --project $Proj | ConvertFrom-Json
39+
foreach ($Repo in $Repos) {
40+
Write-Output $Repo.webUrl
41+
}
42+
}```
43+
44+
Here is some sample output which you can use.
45+
```
46+
PS C:\Dev\ado-api> & .\getRepos.ps1
47+
https://dev.azure.com/exampleorg/java-jsf1/_git/java-jsf1
48+
https://dev.azure.com/exampleorg/Jan2021Example/_git/Jan2021Example
49+
https://dev.azure.com/exampleorg/B2C%20Brownbag/_git/B2C%20Brownbag```
50+
## Credits
51+
Thanks to Simon Wahlinfor the [post](https://blog.simonw.se/cloning-all-repositories-from-azure-devops-using-azure-cli/)
52+

0 commit comments

Comments
 (0)