In Azure DevOps, I am trying to get the result of the latest/last pipeline on a branch for a pipeline. This is to check if the previous build on the branch is failed due to some errors and after fixing the errors, the pipeline should trigger corresponding to the commit to the branch. If the branch has a successful build, the pipeline should skip the build.
I am trying to get result from the using below command to get the result using Azure DevOps API call which works fine in the browser but gives null when run through the pipeline.
previousRunId=$(curl -u ":$(System.AccessToken)" -X GET "$(System.CollectionUri)/$(System.TeamProjectId)/_apis/build/builds?definitions=$(System.DefinitionId)&branchName=$(Build.SourceBranch)&$top=1" | jq '.value[0].result')
echo "Previous run status: ${previousRunId}"
How to get the actual result as below?


There is an exception in your script. You may find the following message If you run your command without
jq:You have to escape
$top