![](/img/trans.png)
[英]How to use Powershell 7 from AzureDevops with AWS Tools
[英]How to get the workitems from AzureDevOps with RestApi in Powershell
Param(
[string]$collectionurl = "https://dev.azure.com",
[string]$project = "projectname",
[string]$token = "PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo =
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}" -f
$token)))
$baseUrl =
"$collectionurl/$project/_apis/wit/reporting/workitemrevisions?
includeLatestOnly=true&api-version=5.0-preview.2"
$response = (Invoke-RestMethod -Uri $baseUrl -Method Get -
UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f
$base64AuthInfo)}).values
$wits = $response | where({$_.fields.'System.WorkItemType' -eq
'Task'}) # Only retrieve Tasks
$witrevisions = @()
foreach($wit in $wits){
$customObject = new-object PSObject -property @{
"WitID" = $wit.fields.'System.Id'
"rev" = $wit.fields.'System.Rev'
"Title" = $wit.fields.'System.Title'
"AssignedTo" = $wit.fields.'System.AssignedTo'
"ChangedDate" = $wit.fields.'System.ChangedDate'
"ChangedBy" = $wit.fields.'System.ChangedBy'
"WorkItemType" = $wit.fields.'System.WorkItemType'
}
$witrevisions += $customObject
}
$witrevisions | Select-Object `
WitID,
rev,
Title,
AssignedTo,
ChangedDate,
ChangedBy,
WorkItemType #|export-csv -Path E:\ashwin\devdata.csv -
NoTypeInformation
Write-Output $witrevisions
我想在我的項目中顯示要使用 powershell 顯示的工作項,並使用我的 PAT 使用以下 Rest Api。
https://dev.azure.com/ {organization}/{project}/_apis/wit/workitems/{id}?api-version=5.1
如何在 Powershell 中使用 RestApi 從 AzureDevOps 獲取工作項
結果將顯示在輸出中,您會發現如下所示:
如果您沒有找到以上輸出,請確保您有任務類型的工作項,因為您已在 powershell 腳本中設置了條件'System.WorkItemType' -eq 'Task'
。
另一方面,您可以將工作項列表導出到*.csv
文件,這部分代碼在 powershell 中進行了注釋:
WorkItemType #| export-csv -Path G:\temp\WIT.csv -NoTypeInformation
如果要創建*.csv
文件,則需要刪除該行中的#
,它應該是:
WorkItemType | export-csv -Path G:\temp\WIT.csv -NoTypeInformation
現在,我們可以在本地文件夾中獲取該文件:
注意:路徑G:\\temp
是本地路徑,您應該使用私有代理,如果您使用的是托管代理,您應該從托管代理復制該文件,並將其發布到管道工件。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.