在构建之间查询工作项,并通过 Azure DevOps REST API 从本地 Azure DevOps 服务器将其转换为 excel 文件

问题描述 投票:0回答:2

我想要在 Excel 文件中构建后更改的工作项目列表。

到目前为止我在这里:

$AzureDevOpsPAT = "**********************************" 
$fromBuildId = "161" 
$toBuildId = "176"


$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) } 

$uriAccount ="https://AzureDevOpsServerName/DefaultCollection/ProjectName/_apis/build/workitems?fromBuildId=$($fromBuildId)&toBuildId=$($toBuildId)&api-version=5.0"

$responsewe = Invoke-RestMethod -Uri $uriAccount -Method Get -Headers $AzureDevOpsAuthenicationHeader 
$d1 = $responsewe.value | ConvertTo-Json write-host $d1
write-host $d1

另外,如何从这些工作项生成发行说明? 我也是 Powershell 和 DevOps 的新手,所以,任何想法都会受到赞赏。

我尝试先获取列表工作项的列表。

azure powershell azure-devops azure-pipelines azure-devops-rest-api
2个回答
0
投票

您可以使用下面的 Powershell 命令获取 csv 文件中构建之间的 WorkItems 输出:-

$PAT = "3fs6xxxxxxxxxxtyjs7cunwa"
$OrgName = "sid24desai0738"
$ProjectName = "AzureDevops"
$ApiVersion = "7.0"

$services = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=1934&toBuildId=1937&api-version=7.1-preview.2" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}

# Export $services to a CSV file
$services | Export-Csv -Path "C:\temp\log-function\File.csv" -NoTypeInformation

输出:-

enter image description here

enter image description here

参考:-

构建 - 在构建之间获取工作项 - REST API(Azure DevOps 构建)|微软学习


0
投票

您已使用正确的 REST API 来获取构建之间的工作项。现在您需要将工作项导出到 Excel,并生成发行说明。

  1. 导出到excel:您可以使用下面的powershell命令在rest api之后导出到excel:
#create the file if it doesn't exist
$path = 'C:\temp\File.csv'
if(!(Test-Path $path)) {
    New-Item -ItemType File -Path $path -Force
}

# Export $workitems to a CSV file
$response.value | Export-Csv -Path $path -NoTypeInformation
  1. 生成发行说明:要生成发行说明,您需要从要包含在发行说明中的每个工作项中决定
    what information
    。一旦您决定了这一点,您就可以循环遍历每个工作项并提取必要的信息。

整个脚本示例:

$PAT = "yourpat"
$OrgName = "yourorgname"
$ProjectName = "projectname"
$buildid1 = "firstbuildid"
$buildid2 = "secondbuildid"
$headers = @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}

#get the work items between builds
$response = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=$buildid1&toBuildId=$buildid2&api-version=7.1-preview.2" -Method Get -Headers $headers

#output the response for a check
echo $response | ConvertTo-Json

#create the file if it doesn't exist
$path = 'C:\temp\File.csv'
if(!(Test-Path $path)) {
    New-Item -ItemType File -Path $path -Force
}


# Export $workitems to a CSV file
$response.value | Export-Csv -Path $path -NoTypeInformation

# get the workitem id and url for the release note as an example
$releaseNotes = foreach ($workItem in $response.value) {
    "Work Item ID: $($workItem.id)`nURL: $($workItem.url)`n---"
}
$releaseNotes | Out-File -FilePath 'c:\temp\ReleaseNotes.txt'

© www.soinside.com 2019 - 2024. All rights reserved.