Search code examples
c#.netazureazure-devopsazure-artifacts

How to download the latest build artifacts from Azure DevOps programmatically?


I have a .NET C# application and I would like to download the latest artifacts generated by the latest build of this public Azure DevOps project:

https://dev.azure.com/LumiaWoA/Boot%20Shim/_build?definitionId=3

How does one interface with Azure DevOps to download the artifacts for such a task?

I have in mind to use an HttpClient to download the zipped artifacts using some special URL.


Solution

  • You would need to use Azure DevOps REST Api for that. This rest call retrieves artifacts from the build:

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

    this REST call would give you latest build:

    GET https://dev.azure.com/{organization}/{project}/_apis/build/latest/{definition}?branchName={branchName}&api-version=5.0-preview.1
    

    Here's an article (with some samples) talking about how you would authenticate to the API. As from the code perspective, its a simple HTTP request, so should be fairly easy.