1
votes

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.

2
How about the issue? Does the answer below resolved your question, If not, would you please let me know the latest information about this issue?Leo Liu-MSFT
I am going it to try it today and hope it works for universal packages alsoSunilS

2 Answers

1
votes

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

0
votes

I've found this way:

  1. Open feed page in Azure, click Connect to feed

  2. Choose Maven, copy the URL from Project setup > repository/url of the pom.xml sample.

    That should look like:

    https://pkgs.dev.azure.com/YOUR-ORGANIZATION/_packaging/YOUR-FEED-NAME/maven/v1
    
  3. Append the artifact info to that link:

    https://pkgs.dev.azure.com/YOUR-ORGANIZATION/_packaging/YOUR-FEED-NAME/maven/v1/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
    

    Hint: compare it to the one from maven repository:

    https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar