我有一个 Azure DevOps 组织,在经过一段时间的非管理使用后,我正在尝试清理该组织。该组织有许多项目使用大约。 45 种不同的流程。我试图找到一种方法来识别哪些字段(我有很多)正在被哪些进程使用,或者更多到哪些字段现在不再使用。
我尝试查看 API,并可以获得字段列表 (https://dev.azure.com/{organization}/_apis/wit/fields) 和进程列表 (https://dev .azure.com/{organization}/_apis/work/processes?api-version=6.0-preview.2),但我似乎无法识别识别哪些进程使用哪些字段之间的链接。
我试图找到一种方法来识别哪些字段(我有很多字段)正在被哪些进程使用,或者更多地确定哪些字段现在不再使用。
没有现有的功能和方法来实现这一点,您可能需要几个 REST API 和自定义脚本,如下所示:
列出所有字段:您已经通过 API 端点涵盖了这部分https://dev.azure.com/{organization}/_apis/wit/fields。
列出所有进程:同样,您有端点 https://dev.azure.com/{organization}/_apis/work/processes?api-version=6.0-preview.2
列出所有进程。
获取流程工作项类型:对于每个流程,您需要获取工作项类型。使用端点:
GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes?api-version=6.0-preview.2
这将为您提供每个流程的工作项类型。
GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=6.0-preview.2
这将列出流程中每个工作项类型使用的字段。
下面的 PowerShell 脚本,将组织名称和个人访问令牌 (pat) 更改为您的:
# Define variables
$organization = "orgname"
$personalAccessToken = "pat"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))
# Function to make API requests
function Invoke-DevOpsRestMethod {
param (
[string]$uri
)
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers @{
Authorization = "Basic $base64AuthInfo"
Accept = "application/json"
}
return $response
}
# Get all fields
$fieldsUri = "https://dev.azure.com/$organization/_apis/wit/fields?api-version=6.0"
$fields = Invoke-DevOpsRestMethod -uri $fieldsUri
# Get all processes
$processesUri = "https://dev.azure.com/$organization/_apis/work/processes?api-version=6.0-preview.2"
$processes = Invoke-DevOpsRestMethod -uri $processesUri
$fieldUsage = @{}
foreach ($process in $processes.value) {
$processId = $process.typeId
# Get work item types for each process
$witUri = "https://dev.azure.com/$organization/_apis/work/processes/$processId/workItemTypes?api-version=6.0-preview.2"
$workItemTypes = Invoke-DevOpsRestMethod -uri $witUri
foreach ($wit in $workItemTypes.value) {
$witRefName = $wit.referenceName
# Get fields for each work item type
$witFieldsUri = "https://dev.azure.com/$organization/_apis/work/processes/$processId/workItemTypes/$witRefName/fields?api-version=6.0-preview.2"
$witFields = Invoke-DevOpsRestMethod -uri $witFieldsUri
foreach ($field in $witFields.value) {
$fieldRefName = $field.referenceName
if (-not $fieldUsage.ContainsKey($fieldRefName)) {
$fieldUsage[$fieldRefName] = @()
}
$fieldUsage[$fieldRefName] += $process.name
}
}
}
# Print fields and their usage
foreach ($field in $fieldUsage.Keys) {
$processList = $fieldUsage[$field] -join ", "
Write-Host "Field: $field is used in processes: $processList"
}
# Print fields that are not used by any process
$unusedFields = $fields.value | Where-Object { -not $fieldUsage.ContainsKey($_.referenceName) }
foreach ($unusedField in $unusedFields) {
Write-Host "Field: $($unusedField.referenceName) is not used in any process"
}
输出: