Azure Artifacts - 下载特定版本的 maven artifact
答案是肯定的。我们可以使用 REST API Maven - Download Package 从 azure artifacts 下载特定的 jar:
GET https://pkgs.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/maven/{groupId}/{artifactId}/{version}/{fileName}/content?api-version=5.1-preview.1
首先,我们需要获取feedId。我们可以使用 REST API Feed Management - Get Feeds 来获取 feedId:
GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/feeds?api-version=5.1-preview.1
注意:如果提要是在项目中创建的,则必须提供项目参数。如果提要未与任何项目关联,请在请求中省略项目参数。
对于 URL 中的其他参数,我们可以从包的概述中获取。选择包并打开包,我们可以看到如下视图:
现在,我们有了所有参数,feedId、groupId、artifactId、version、fileName。
所以,我们可以使用带有-OutFile $(Build.SourcesDirectory)\myFirstApp-1.0-20190818.032400-1.jar 的 REST API 来下载包(内联 powershell 任务):
$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
由于我的 Maven 提要是组织范围的提要,因此我在 URL 中省略了项目参数。
结果: