azure - 如何使用 az cli 编写 Azure 存储库搜索脚本

标签 azure azure-devops

我对 Azure cli 还很陌生。我有一个案例,我想对 Azure devops 中的每个代码存储库执行搜索,并检查 pom.xml 文件中依赖项的版本。

通过网络控制台的前端搜索提供了非常接近我需要的内容,但我无法轻松导出结果。在前端,我输入这样的搜索,它给了我我需要的东西。

enter image description here

复制此行为以使用 azure cli 生成某种报告的最佳方法是什么?

最佳答案

在 az cli 中,有 az repos管理 Azure Repos。您可以运行 az repos show 来获取 Git 存储库的详细信息,但没有代码搜索命令。

您可以使用 Code Search Results - Fetch Code Search Results 而不是 az cli在脚本中使用 REST api 来获取搜索文本的结果。

POST https://almsearch.dev.azure.com/{organization}/{project}/_apis/search/codesearchresults?api-version=6.0-preview.1

该脚本使用的 api 如下所示:

Param( 
[string]$organisation = "org", 
[string]$project = "projectname", 
[string]$keepForever = "true", 
[string]$user = " ", 
[string]$token = "PAT" ) 

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$postresults = "https://almsearch.dev.azure.com/$organisation/$project/_apis/search/codesearchresults?api-version=6.0-preview.1" 

 $body = '{

}'

$result = Invoke-RestMethod -Uri $postresults -Method Post -Body $body -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

关于azure - 如何使用 az cli 编写 Azure 存储库搜索脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67191897/

相关文章:

azure-devops - Azure DevOps 查询匹配未分配的任务?

azure - 由于 'Forbidden',无法上传 Windows dll(使用 PublishBuildArtifacts 到 Azure DevOps)

azure-devops - 如何通过 CredentialProvider.VSS.exe 清除凭据缓存

azure-devops - Azure DevOps 为内联 bash 脚本中的操作创建变量

sql - 使用 Powershell 为 PAAS 服务器添加包含 IP 地址的防火墙规则

azure - 应使用哪个驱动器来在 Azure 虚拟机中保存数据?

azure - 单个域上的两个 Azure 应用服务

c# - 由于写权限,单元测试在 Visual Studio Team Services Build runner 上失败?

postgresql - 无法连接到 azure PostgreSQL 数据库 - 用户名应采用 <username@hostname> 格式

azure - 以编程方式拉取 docker 镜像并上传到 Azure 应用服务