Search code examples
azure-devopsbuild-pipeline

Want to read xml file from published artifacts in azure devops build pipeline


I am using the azure-DevOps build pipeline to run & publish the postman Newman report as pipeline artifacts. my pipeline does publish pipeline artifacts (HTML-reports of postman and also gives Newman report in XML files).

My requirement is that using azure-DevOps API I want to read the XML file. & this API I have to call from my program (nodeJs/Python).

Any idea how? Thanks in Advance Note: I see ADO is still working on fileId (not sure how to get fileID) https://github.com/MicrosoftDocs/vsts-rest-api-specs/issues/381


Solution

  • The artifact published in azure pipeline provides dowload url to get the files. You can get the download url directly from the build summary portal. See below:

    Go the published artifacts-->Click the 3dots of the file you want to download

    enter image description here

    You can call the download url directly to read the xml file in your code. See below example in powershell script:

    $url = "https://dev.azure.com/{org}/_apis/resources/Containers/{containerId}/{artifactName}?itemPath=artifactName%2Fbuild.xml"
    
    $PAT="Personal access token"
    $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
    
    $xmlContent = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method get
    

    If you donot want to get the download url from the UI portal. You can call Artifacts - Get Artifact to get the container id. Then you can get the download url for the xml file after you get the container id.

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

    See below example result from above rest api.

    enter image description here

    Download url:

    https://dev.azure.com/{org}/_apis/resources/Containers/{containerId}/{artifactName}?itemPath={artifactName}%2F{xmlfileName.xml}