Retrieve log file of specific Build task in multi job pipeline in Azure DevOps releases

1.8k Views Asked by At

We have Azure DevOps extension in which one of build task we used to obtain data from release build log to display in release summary tab. This build task works perfect for the single Agent Job pipelines, but we have come across a scenario that there are multiple Agent jobs available and we couldn’t retrieve data once our build task added to second or later agent job.

enter image description here

Below is how we get data from task logs. However, this method only iterates trough first job and does not access second. We are using release management client from "ReleaseManagement/Core/RestClient" in the VSS SDK

   //getting list of tasks
    var t = await rmClient.getTasks(VSS.getWebContext().project.id, release.id, environment.id);
    // iterate trough task list until required task found
    for (var i = 0; i < t.length; i++) {
        var currentTask = t[i];               
        
        var logData = await rmClient.getLog(VSS.getWebContext().project.id, release.id, environment.id, currentTask.id, environment.deploySteps.length);  

        // Identify task based on data in it
        break;
    }

As per the SDK implementation there are two methods available for retrieve logs getlog which returns log of task as a string (the one we use now) and getLogs which returns all Logs as ArrayBuffer

/**
     * [Preview API] Gets logs
     *
     * @param {string} project - Project ID or project name
     * @param {number} releaseId - Id of the release.
     * @param {number} environmentId - Id of release environment.
     * @param {number} taskId - ReleaseTask Id for the log.
     * @param {number} attemptId - Id of the attempt.
     * @return IPromise<string>
     */
    getLog(project: string, releaseId: number, environmentId: number, taskId: number, attemptId?: number): IPromise<string>;
    /**
     * [Preview API] Get logs for a release Id.
     *
     * @param {string} project - Project ID or project name
     * @param {number} releaseId - Id of the release.
     * @return IPromise<ArrayBuffer>
     */
    getLogs(project: string, releaseId: number): IPromise<ArrayBuffer>;

As you can observe there is no place to specify agent job in these methods.

If someone has experience with this,

  1. Is it possible to obtain log data from second or later job in the release pipeline? sample / documentation would be much helpful.
  2. I tried to get data from array buffer, but it ends up getting out of boundary error when I try to convert ArrayBuffer to string.

Any thoughts, advise highly appreciated

1

There are 1 best solutions below

0
On

To get a task log from an Agent Job, you also need releaseDeployPhaseId. Check the following api:

https://learn.microsoft.com/en-us/rest/api/azure/devops/release/releases/get%20task%20log?view=azure-devops-rest-6.0

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}/deployPhases/{releaseDeployPhaseId}/tasks/{taskId}/logs?api-version=6.0-preview.2

You could call REST APIs from your extension as this documentation mentioned:

https://learn.microsoft.com/en-us/azure/devops/extend/develop/auth?view=azure-devops#calling-rest-apis-from-your-extension