$testingBaseUrl = "https://dev.azure.com/cbre/Research%20Engine/_apis/test/runs" $testingUrl = $testingBaseUrl + "?api-version=5.0" $testingUrl = $testingUrl + "-preview.2" write-host $testingUrl #create auth header to use for REST calls $username = "RKesavana" $token = "your token" Refer to my blog of how to create Personal access tokens #create auth header to use for REST calls $accessToken = ("{0}:{1}" -f $username,$token) $accessToken = [System.Text.Encoding]::UTF8.GetBytes($accessToken) $accessToken = [System.Convert]::ToBase64String($accessToken) $headers = @{Authorization=("Basic {0}" -f $accessToken)} try{ # write-host "To fetch LIST all the Test ID's information" $testRuns=Invoke-RestMethod -Uri $testingUrl -Method Get -Headers $headers $testRunsIdSorted = $testRuns.value | sort-object id -Descending # write-host $testRunsIdSorted $testURLByRunID= $testingBaseUrl+"/"+$($testRunsIdSorted[0].id) $testURLByRunID= $testURLByRunID+ "?api-version=5.0" $testURLByRunID = $testURLByRunID + "-preview.2" write-host "To fetch the MOST RECENT run Test RUN ID" write-host $testURLByRunID $mostRecentTestRun = Invoke-RestMethod -Uri $testURLByRunID -Headers $headers -Method Get | Select-Object id,name,url,build,isAutomated,iteration,owner,project,startedDate,completedDate,state,totalTests,incompleteTests,notApplicableTests,passedTests,unanalyzedTests,revision,webAccessUrl #PRINT the values from the REST calls write-host "owner" $mostRecentTestRun.owner write-host "startedDate" $mostRecentTestRun.startedDate write-host "completedDate" $mostRecentTestRun.completedDate write-host "totalTests" $mostRecentTestRun.totalTests write-host "incompleteTests" $mostRecentTestRun.incompleteTests write-host "notApplicableTests" $mostRecentTestRun.notApplicableTests write-host "passedTests" $mostRecentTestRun.passedTests write-host "unanalyzedTests" $mostRecentTestRun.unanalyzedTests write-host "revision" $mostRecentTestRun.revision write-host "webAccessUrl" $mostRecentTestRun.webAccessUrl write-Host "##vso[task.setvariable variable=mostRecentRun;]$mostRecentTestRun } Catch { $exception = $_.Exception $respstream = $exception.Response.GetResponseStream() $sr = new-object System.IO.StreamReader $respstream $ErrorResult = $sr.ReadToEnd() write-host $ErrorResult }
My Quotes
When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY
Powered by Find-IP.net
Thursday, January 3, 2019
Capture last TEST Run results AZURE DevOps
You could retrieve the list of test runs, the sort descending the result on ID, since the most recent test run has the greatest ID. Then get the first item of the result. All of this shown below in powershell:
Subscribe to:
Post Comments
(
Atom
)
No comments :