Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何在Azure DevOps中获取所有回购协议_Powershell_Azure Devops_Azure Devops Rest Api - Fatal编程技术网

Powershell 如何在Azure DevOps中获取所有回购协议

Powershell 如何在Azure DevOps中获取所有回购协议,powershell,azure-devops,azure-devops-rest-api,Powershell,Azure Devops,Azure Devops Rest Api,我在Azure DevOps中有很多项目。我希望能够遍历Azure DevOps中的所有Repo,并获得Repo的名称、Repo的创建者和上次更新/提交 并在有人创建新回购协议时收到通知?我们可以通过REST API列出回购信息 并获取回购协议的名称: : 注意:我们可以通过这个API获取分支创建者,我没有找到任何API来获取回购创建者 : 当有人创建新回购协议时获取通知 我们无法创建此通知,我们可以在有人更新回购代码时收到通知。有关更多详细信息,请参阅此链接: 更新1 //List proj

我在Azure DevOps中有很多项目。我希望能够遍历Azure DevOps中的所有Repo,并获得Repo的名称、Repo的创建者和上次更新/提交


并在有人创建新回购协议时收到通知?

我们可以通过REST API列出回购信息

并获取回购协议的名称:

:

注意:我们可以通过这个API获取分支创建者,我没有找到任何API来获取回购创建者

:

当有人创建新回购协议时获取通知

我们无法创建此通知,我们可以在有人更新回购代码时收到通知。有关更多详细信息,请参阅此链接:

更新1

//List project name
$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.1-preview.1" 
$Repo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$RepoName= $Repo.value.name
Write-Host  $RepoName

//get latest commit info and branch creator
$RepoID=$Repo.value.id
Write-Host  $RepoID
ForEach ($Id in $RepoID)
{

//Get latest commit info
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits?api-version=6.1-preview.1" 
$CommitInfo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$CommitID = $CommitInfo.value.commitId | Select-Object -first 1
Write-Host $CommitID
$CommitUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits/$($CommitID)?api-version=6.0-preview.1"
$LatestCommitInfo = (Invoke-RestMethod -Uri $CommitUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host "LatestCommitInfo = $($LatestCommitInfo | ConvertTo-Json -Depth 100)"

//Get branch name and creatot
$BarchCreatorUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/refs?api-version=6.1-preview.1"
$CreateorInfo = (Invoke-RestMethod -Uri $BarchCreatorUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host $CreateorInfo.value.name
Write-Host $CreateorInfo.value.creator.displayName
}

是否有任何PowerShell脚本代码可以在一次执行中执行上述所有操作?嗨@Pradeep,我已经更新了答案,请检查。谢谢@Vito,一旦我测试上述脚本,我将接受你的答案。嗨@Pradeep,请随时告诉我结果。如果你还有任何问题,我仍然会在这里帮助你。它按预期工作,但我想找到回购协议的创建者。我想以表格格式显示输出。
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=6.1-preview.1
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?searchCriteria.$top=1&api-version=6.1-preview.1
//List project name
$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.1-preview.1" 
$Repo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$RepoName= $Repo.value.name
Write-Host  $RepoName

//get latest commit info and branch creator
$RepoID=$Repo.value.id
Write-Host  $RepoID
ForEach ($Id in $RepoID)
{

//Get latest commit info
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits?api-version=6.1-preview.1" 
$CommitInfo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$CommitID = $CommitInfo.value.commitId | Select-Object -first 1
Write-Host $CommitID
$CommitUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits/$($CommitID)?api-version=6.0-preview.1"
$LatestCommitInfo = (Invoke-RestMethod -Uri $CommitUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host "LatestCommitInfo = $($LatestCommitInfo | ConvertTo-Json -Depth 100)"

//Get branch name and creatot
$BarchCreatorUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/refs?api-version=6.1-preview.1"
$CreateorInfo = (Invoke-RestMethod -Uri $BarchCreatorUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host $CreateorInfo.value.name
Write-Host $CreateorInfo.value.creator.displayName
}