我正在尝试制作一个包含Azure CLI命令的PowerShell脚本,以检索有关repo的信息,我是Azure DevOps的新手。
我试图收集的信息是转发列表、它们的分支、最近的提交和作者。
我已经浏览了AZ Repos文档,但无法正确执行,以下是我迄今为止所做的代码。
$orgUrl = "https://dev.azure.com/{MyOrganization}"
$ProjectUrl = "https://dev.azure.com/{MyOrganization}/_apis/git/repositories?api-verepo_demo/sion=4.1"
$env:SYSTEM_ACCESSTOKEN | az devops login --org $org --project $ProjectUrl
foreach ($Proj in $ProjectUrl)
{
$Repos = az repos list --organization $orgUrl --project $Proj | ConvertFrom-Json
foreach ($Repo in $Repos) {
Write-Output $Repo.webUrl
}
看起来你已经达到了目标。。。但是在你粘贴的代码中有一些非常错误的地方,我猜代码是不完整的。
$orgUrl = "https://dev.azure.com/{MyOrganization}"
# there is an error in the project url below, it should contain the project name. Plus, you need to pass the project name, not the full URI.
$ProjectUrl = "https://dev.azure.com/{MyOrganization}/_apis/git/repositories?api-verepo_demo/sion=4.1"
$env:SYSTEM_ACCESSTOKEN | az devops login --org $org --project $ProjectUrl
# you can't for each through a url. I assume you had some az DevOps list command here previously.
foreach ($Proj in $ProjectUrl)
{
# you should probably enforce json output here.
$Repos = az repos list --organization $orgUrl --project $Proj | ConvertFrom-Json
foreach ($Repo in $Repos) {
Write-Output $Repo.webUrl
}
}
如果你只查询一个项目,你可以简单地硬编码项目名称:
$orgUrl = "https://dev.azure.com/{MyOrganization}"
$project = "demo"
$env:SYSTEM_ACCESSTOKEN | az devops login --org $org --project $project
$Repos = az repos list --organization $orgUrl --project $project -o json | ConvertFrom-Json
foreach ($Repo in $Repos) {
Write-Output $Repo.webUrl
}