Update to latest script in common and fix issues in BulkUpdate (#3298)
This commit is contained in:
Родитель
718b8249cd
Коммит
85abdf6da0
|
@ -3,6 +3,38 @@ $ReleaseDevOpsOrgParameters = @("--organization", "https://dev.azure.com/azure-
|
|||
$ReleaseDevOpsCommonParameters = $ReleaseDevOpsOrgParameters + @("--output", "json")
|
||||
$ReleaseDevOpsCommonParametersWithProject = $ReleaseDevOpsCommonParameters + @("--project", "Release")
|
||||
|
||||
function Get-DevOpsRestHeaders()
|
||||
{
|
||||
$headers = $null
|
||||
if (Get-Variable -Name "devops_pat" -ValueOnly -ErrorAction "Ignore")
|
||||
{
|
||||
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
|
||||
$headers = @{ Authorization = "Basic $encodedToken" }
|
||||
}
|
||||
else
|
||||
{
|
||||
# Get a temp access token from the logged in az cli user for azure devops resource
|
||||
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
|
||||
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
|
||||
}
|
||||
|
||||
return $headers
|
||||
}
|
||||
|
||||
function CheckDevOpsAccess()
|
||||
{
|
||||
# Dummy test query to validate permissions
|
||||
$query = "SELECT [System.ID] FROM WorkItems WHERE [Work Item Type] = 'Package' AND [Package] = 'azure-sdk-template'"
|
||||
|
||||
$response = Invoke-RestMethod -Method POST `
|
||||
-Uri "https://dev.azure.com/azure-sdk/Release/_apis/wit/wiql/?api-version=6.0" `
|
||||
-Headers (Get-DevOpsRestHeaders) -Body "{ ""query"": ""$query"" }" -ContentType "application/json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
|
||||
if ($response -isnot [HashTable] -or !$response.ContainsKey("workItems")) {
|
||||
throw "Failed to run test query against Azure DevOps. Please ensure you are logged into the public azure cloud. Consider running 'az logout' and then 'az login'."
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-AzBoardsCmd($subCmd, $parameters, $output = $true)
|
||||
{
|
||||
$azCmdStr = "az boards ${subCmd} $($parameters -join ' ')"
|
||||
|
@ -26,24 +58,12 @@ function Invoke-Query($fields, $wiql, $output = $true)
|
|||
Write-Host "Executing query $wiql"
|
||||
}
|
||||
|
||||
$headers = $null
|
||||
if (Get-Variable -Name "devops_pat" -ValueOnly -ErrorAction "Ignore")
|
||||
{
|
||||
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
|
||||
$headers = @{ Authorization = "Basic $encodedToken" }
|
||||
}
|
||||
else
|
||||
{
|
||||
# Get a temp access token from the logged in az cli user for azure devops resource
|
||||
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
|
||||
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
|
||||
}
|
||||
$response = Invoke-RestMethod -Method POST `
|
||||
-Uri "https://dev.azure.com/azure-sdk/Release/_apis/wit/wiql/?`$top=10000&api-version=6.0" `
|
||||
-Headers $headers -Body $body -ContentType "application/json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
-Headers (Get-DevOpsRestHeaders) -Body $body -ContentType "application/json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
|
||||
if (!$response.workItems) {
|
||||
Write-Warning "Query returned no items. $wiql"
|
||||
if ($response -isnot [HashTable] -or !$response.ContainsKey("workItems") -or $response.workItems.Count -eq 0) {
|
||||
Write-Verbose "Query returned no items. $wiql"
|
||||
return ,@()
|
||||
}
|
||||
|
||||
|
@ -63,11 +83,11 @@ function Invoke-Query($fields, $wiql, $output = $true)
|
|||
Write-Verbose "Pulling work items $uri "
|
||||
|
||||
$batchResponse = Invoke-RestMethod -Method GET -Uri $uri `
|
||||
-Headers $headers -ContentType "application/json" -MaximumRetryCount 3 | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
-Headers (Get-DevOpsRestHeaders) -ContentType "application/json" -MaximumRetryCount 3 | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
|
||||
if ($batchResponse.value)
|
||||
{
|
||||
$batchResponse.value | % { $workItems += $_ }
|
||||
$batchResponse.value | ForEach-Object { $workItems += $_ }
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -891,20 +911,8 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
|
|||
|
||||
$body = "[" + ($fieldUpdates -join ',') + "]"
|
||||
|
||||
$headers = $null
|
||||
if (Get-Variable -Name "devops_pat" -ValueOnly -ErrorAction "Ignore")
|
||||
{
|
||||
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
|
||||
$headers = @{ Authorization = "Basic $encodedToken" }
|
||||
}
|
||||
else
|
||||
{
|
||||
# Get a temp access token from the logged in az cli user for azure devops resource
|
||||
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
|
||||
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
|
||||
}
|
||||
$response = Invoke-RestMethod -Method PATCH `
|
||||
-Uri "https://dev.azure.com/azure-sdk/_apis/wit/workitems/${id}?api-version=6.0" `
|
||||
-Headers $headers -Body $body -ContentType "application/json-patch+json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
-Headers (Get-DevOpsRestHeaders) -Body $body -ContentType "application/json-patch+json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
|
||||
return $response
|
||||
}
|
|
@ -38,6 +38,8 @@ if (!$?){
|
|||
. (Join-Path $PSScriptRoot SemVer.ps1)
|
||||
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)
|
||||
|
||||
CheckDevOpsAccess
|
||||
|
||||
$parsedNewVersion = [AzureEngSemanticVersion]::new($version)
|
||||
$state = "In Release"
|
||||
$releaseType = $parsedNewVersion.VersionType
|
||||
|
|
|
@ -8,11 +8,17 @@ param(
|
|||
Set-StrictMode -Version 3
|
||||
|
||||
if (!(Get-Command az -ErrorAction SilentlyContinue)) {
|
||||
Write-Host 'You must have the Azure CLI installed: https://aka.ms/azure-cli'
|
||||
Write-Error 'You must have the Azure CLI installed: https://aka.ms/azure-cli'
|
||||
exit 1
|
||||
}
|
||||
|
||||
az extension show -n azure-devops > $null
|
||||
az account show *> $null
|
||||
if (!$?) {
|
||||
Write-Host 'Running az login...'
|
||||
az login *> $null
|
||||
}
|
||||
|
||||
az extension show -n azure-devops *> $null
|
||||
if (!$?){
|
||||
Write-Host 'Installing azure-devops extension'
|
||||
az extension add --name azure-devops
|
||||
|
@ -22,11 +28,15 @@ if (!$?){
|
|||
. (Join-Path $PSScriptRoot .. common scripts Helpers DevOps-WorkItem-Helpers.ps1)
|
||||
. (Join-Path $PSScriptRoot PackageList-Helpers.ps1)
|
||||
|
||||
CheckDevOpsAccess
|
||||
|
||||
$unchangedPkgList = Get-CombinedPackageListForPlannedVersions $pkgFilter
|
||||
|
||||
$uniqueName = ""
|
||||
if (!$CSVPath)
|
||||
{
|
||||
$CSVPath = "plannedpackages_$([System.IO.Path]::GetRandomFileName()).csv"
|
||||
$uniqueName = "plannedpackages_$([System.IO.Path]::GetRandomFileName()).csv"
|
||||
$CSVPath = $uniqueName
|
||||
$seedString = "Seeded CSV file with existing packages "
|
||||
if ($pkgFilter) { $seedString += "that match '$pkgFilter' " }
|
||||
$seedString += "and opening it in excel."
|
||||
|
@ -71,6 +81,11 @@ $changedPkgList = Get-Content $CSVPath | ConvertFrom-Csv | Where-Object {
|
|||
|
||||
if (!$changedPkgList -or $changedPkgList.Count -eq 0) {
|
||||
Write-Host "Didn't find any packages with a planned version and date in [$CSVPath]."
|
||||
|
||||
if ($uniqueName) {
|
||||
Write-Host "In some cases excel is delayed in saving a file so if you made changes try re-running the script passing in the file like:"
|
||||
Write-Host ".\eng\scripts\BulkUpdatePackagePlannedDates.ps1 $CSVPath"
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче