Search code examples
azure-devopsazure-devops-rest-apiazure-devops-pipelines

Azure DevOps pipeline logs for a specific task


In Azure DevOps, I have a pipeline, where I need the logs of a specific task. How do I find out which log ID i need to fetch it?

eg. on UI this is the endpoint: https://dev.azure.com/myorg/myspace/_build/results?buildId=1234&view=logs&j=899c4bff-9ac3-12de-4775-50e701812cb4&t=bc949ec8-c945-5220-1d40-d8ea7dab4bda which contains the job and task ids, but these are useless when querying logs.

Same example, url to the logs I need: https://dev.azure.com/myorg/cd642969-da00-4584-ab6a-4b6021c47eff/_apis/build/builds/1234/logs/24

The number of tasks depends on what parameters I set, so the number 24 changes. How do I calculate the log id, if I know the name / id of the job and task?

Should I go through all the ~100 task logs and grep for match in the first lines for the task name? (troll)


Solution

  • How do I calculate the log id, if I know the name / id of the job and task?

    To get the logid with task name, you could try to use the following Rest API: Timeline - Get

    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline?api-version=6.0
    

    You could search with task name. Then you could get the target logid:

    enter image description here