@@ -64,8 +64,8 @@ function Invoke-AzDORestApi (
64
64
$base64AuthInfo = [Convert ]::ToBase64String([System.Text.ASCIIEncoding ]::ASCII.GetBytes(" :${Token} " ))
65
65
$authHeader = " Basic ${base64AuthInfo} "
66
66
} 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 "
69
69
exit 1
70
70
}
71
71
if (! $script :aadTokenExpiresOn -or $aadTokenExpired ) {
@@ -93,7 +93,6 @@ function Invoke-AzDORestApi (
93
93
- Uri $Url `
94
94
| Set-Variable - Name apiResponse
95
95
96
- Write-Debug " Api response: ${Url} "
97
96
$apiResponse | Format-List | Out-String | Write-Debug
98
97
return $apiResponse
99
98
}
@@ -206,7 +205,7 @@ try {
206
205
# BUG: Continuation token is not working when the same pipeline name exists in more than <top> folders
207
206
# BUG: orderBy is not working, $orderBy is
208
207
# 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 `
210
209
| Set-Variable - Name pipelinesRequestUrl
211
210
212
211
$pipelinesBatch = $null
@@ -243,17 +242,19 @@ try {
243
242
Write-Debug " Pipeline run"
244
243
$pipeline | Format-List | Out-String | Write-Debug
245
244
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
248
247
249
248
$pipelineRun = $null
250
249
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
257
258
258
259
Write-Debug " Pipeline run:"
259
260
$pipelineRun | Format-List | Out-String | Write-Debug
@@ -262,7 +263,7 @@ try {
262
263
Write-Debug " No pipeline runs found for pipeline $ ( $pipeline.name ) "
263
264
continue
264
265
}
265
-
266
+
266
267
" {0}/_apis/build/builds/{1}/timeline?api-version={2}" -f $projectUrl , $pipelineRun.id , $apiVersion `
267
268
| Set-Variable - Name timelineRequestUrl
268
269
$timelineRecords = $null
@@ -350,7 +351,4 @@ try {
350
351
| Out-String - Width 256
351
352
352
353
Write-Host " Deprecated task usage in '${OrganizationUrl} ' has been saved to ${exportFilePath} "
353
-
354
- $global :foo = $allDeprecatedTimelineTasks
355
-
356
354
}
0 commit comments