Skip to content

Commit 4b353a8

Browse files
authored
Deprecated task updates (#24)
* Clean up * Fix az-cli test * Use succeeded runs only * Ensure latest run is used
1 parent eedc517 commit 4b353a8

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

pipelines/list-deprecated-tasks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747

4848
steps:
4949
- pwsh: |
50-
Write-Host "`$ProgressPreference: ${ProgressPreference}"
5150
./list_deprecated_tasks.ps1 -ListTasksOnly:(!$${{ parameters.includeUsage }})
5251
displayName: 'Find deprecated tasks'
5352
workingDirectory: $(scriptDirectory)

scripts/pipelines/list_deprecated_tasks.ps1

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function Invoke-AzDORestApi (
6464
$base64AuthInfo = [Convert]::ToBase64String([System.Text.ASCIIEncoding]::ASCII.GetBytes(":${Token}"))
6565
$authHeader = "Basic ${base64AuthInfo}"
6666
} else {
67-
if (!(Get-Command az)) {
68-
Write-Error "Install Azure CLI (http://aka.ms/azure-cli) to log in to Azure DevOps"
67+
if (!(Get-Command az -ErrorAction SilentlyContinue)) {
68+
Write-Error "Install Azure CLI (http://aka.ms/azure-cli) to log in to Azure DevOps without specifying a token"
6969
exit 1
7070
}
7171
if (!$script:aadTokenExpiresOn -or $aadTokenExpired) {
@@ -93,7 +93,6 @@ function Invoke-AzDORestApi (
9393
-Uri $Url `
9494
| Set-Variable -Name apiResponse
9595

96-
Write-Debug "Api response: ${Url}"
9796
$apiResponse | Format-List | Out-String | Write-Debug
9897
return $apiResponse
9998
}
@@ -206,7 +205,7 @@ try {
206205
# BUG: Continuation token is not working when the same pipeline name exists in more than <top> folders
207206
# BUG: orderBy is not working, $orderBy is
208207
# BUG: $orderBy does not order on 'folder asc'
209-
"{0}/_apis/pipelines?continuationToken={1}&api-version={2}&`$top=1000" -f $projectUrl, $pipelineContinuationToken, $apiVersion `
208+
"{0}/_apis/pipelines?continuationToken={1}&`$top=1000&api-version={2}" -f $projectUrl, $pipelineContinuationToken, $apiVersion `
210209
| Set-Variable -Name pipelinesRequestUrl
211210

212211
$pipelinesBatch = $null
@@ -243,17 +242,19 @@ try {
243242
Write-Debug "Pipeline run"
244243
$pipeline | Format-List | Out-String | Write-Debug
245244

246-
"{0}/_apis/pipelines/{1}/runs?&api-version={2}&`$top=200" -f $projectUrl, $pipeline.id, $apiVersion `
247-
| Set-Variable -Name pipelineRunsRequestUrl
245+
"{0}/_apis/pipelines/{1}/runs?`$top=200&api-version={2}" -f $projectUrl, $pipeline.id, $apiVersion `
246+
| Set-Variable -Name pipelineRunsRequestUrl
248247

249248
$pipelineRun = $null
250249
Invoke-AzDORestApi $pipelineRunsRequestUrl `
251-
| Tee-Object -Variable pipelineRunsResponse `
252-
| ConvertFrom-Json `
253-
| Select-Object -ExpandProperty value `
254-
| Tee-Object -Variable pipelineRuns `
255-
| Select-Object -First 1 `
256-
| Set-Variable pipelineRun
250+
| Tee-Object -Variable pipelineRunsResponse `
251+
| ConvertFrom-Json `
252+
| Select-Object -ExpandProperty value `
253+
| Tee-Object -Variable pipelineRuns `
254+
| Where-Object {$_.result -ieq "succeeded"} `
255+
| Sort-Object -Property createdDate -Descending `
256+
| Select-Object -First 1 `
257+
| Set-Variable pipelineRun
257258

258259
Write-Debug "Pipeline run:"
259260
$pipelineRun | Format-List | Out-String | Write-Debug
@@ -262,7 +263,7 @@ try {
262263
Write-Debug "No pipeline runs found for pipeline $($pipeline.name)"
263264
continue
264265
}
265-
266+
266267
"{0}/_apis/build/builds/{1}/timeline?api-version={2}" -f $projectUrl, $pipelineRun.id, $apiVersion `
267268
| Set-Variable -Name timelineRequestUrl
268269
$timelineRecords = $null
@@ -350,7 +351,4 @@ try {
350351
| Out-String -Width 256
351352

352353
Write-Host "Deprecated task usage in '${OrganizationUrl}' has been saved to ${exportFilePath}"
353-
354-
$global:foo = $allDeprecatedTimelineTasks
355-
356354
}

0 commit comments

Comments
 (0)