In azure release pipelines logs, there is one link get generated in task log output i want to use it as a variable in next tasks. I was thinking to parse it from the logs but unable to find the logs in agent.
How i can solve this issue. Where the logs are getting stored in agent in which directory? i have checked the $(System.DefaultWorkingDirectory) but could not find the logs.
You can use the REST API Timeline - Get in the pipeline to get the detail of the pipeline. In the response of the Timeline- Get, we can find the log url of the tasks. Then we can get the log of the task to find the result link you need.
Here is my test sample yaml:
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- script: |
echo "Testing"
echo "Results link: https://dev.azure.com/"
echo "Need to abort? ..."
displayName: "Runtests"
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$orgname="your org name"
$projectname="your project name"
$url = "https://dev.azure.com/$orgname/$projectname/_apis/build/builds/$(Build.BuildId)/timeline?api-version=7.1"
$TimelineResponse = Invoke-RestMethod -Uri $url -Headers @{"Authorization" = "Bearer $(System.AccessToken)"}
$loglink = $TimelineResponse.records | Where-Object { $_.name -eq "Runtests" } | Select-Object -ExpandProperty log | Select-Object -ExpandProperty url
Write-Output "The log link of task Run tests is $loglink"
$log = Invoke-RestMethod -Uri $loglink -Headers @{"Authorization" = "Bearer $(System.AccessToken)"}
$Resultslink = ($log | Select-String -Pattern "Results link: (.*)").Matches.Groups[1].Value
Write-Output "Results link is $Resultslink"
Test result: