Search code examples
azureazure-devopsazure-devops-rest-apiazure-devops-extensions

Azure Artifacts - Download a specific version of maven artifact


We are using azure devops for our CI/CD process. Many a times, in order to do some custom builds, we need to download the specific maven jar from artifact repo.

Is there a way (commandline or API) to do the same ?

Again the question is about download specific jar from azure artifacts.


Solution

  • Azure Artifacts - Download a specific version of maven artifact

    The answer is yes. We could use the REST API Maven - Download Package to download the specific jar from azure artifacts:

    GET https://pkgs.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/maven/{groupId}/{artifactId}/{version}/{fileName}/content?api-version=5.1-preview.1
    

    First, we need to get the feedId. We could use the REST API Feed Management - Get Feeds to get the feedId:

    GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/feeds?api-version=5.1-preview.1
    

    Note: The project parameter must be supplied if the feed was created in a project. If the feed is not associated with any project, omit the project parameter from the request.

    For other parameters in the URL, we could get it from the overview of the package. Select the package and open the package, we could get following view:

    enter image description here

    Now, we have all the parameters, feedId, groupId, artifactId, version, fileName.

    So, we could use the REST API with -OutFile $(Build.SourcesDirectory)\myFirstApp-1.0-20190818.032400-1.jar to download the package (Inline powershell task):

    $url = "https://pkgs.dev.azure.com/<OrganizationName>/_apis/packaging/feeds/83cd6431-16cc-480d-bb4d-a213e17b3a2b/maven/MyGroup/myFirstApp/1.0-SNAPSHOT/myFirstApp-1.0-20190818.032400-1.jar/content?api-version=5.1-preview.1"
    $buildPipeline= Invoke-RestMethod -Uri $url -OutFile $(Build.SourcesDirectory)\myFirstApp-1.0-20190818.032400-1.jar -Headers @{   
     Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
    } -Method Get
    

    Since my maven feed is an organization scoped feed, I omit the project parameter from the URL.

    The result:

    enter image description here

    enter image description here