Search code examples
powershellazure-devopsyamlazure-pipelines

Listing the names of manual approvers of azure devops pipeline builds


I am looking to write a PowerShell script to retrieve the names of the approvers of manual validation tasks within azure devops pipelines.

We use ManualValidation@0 tasks within the yaml code of our release pipelines for our approvals. The names of the people who approved these pipelines are visible within azure devops itself but I cannot find a way to retrieve these using a script. Any help would be greatly appreciated.

I have attempted using a powershell script with the Azure REST API to pull the timeline of pipeline builds and have found some details about the ManualValidation@0 tasks but nothing seeming to link to the user who actually made the approval.


Solution

  • You need to use these two REST APIs: Timeline List and Approvals Query

    First, get the approvalId using the Timeline API by searching for the identifier in the API response for the corresponding ManualValidation task/record:
    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline?api-version=7.1-preview.2

    Then, pass the approvalId (identifier) along with $expand=steps in the Approvals API to get details about the actual approvers:

    GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/approvals?approvalIds={approvalIds}&$expand=steps&api-version=7.0-preview.1