上传和下载 azure 工件的等效 maven 命令和设置是什么? [英] What are the equivalent maven commands and settings to upload and download azure artifacts?

查看:13
本文介绍了上传和下载 azure 工件的等效 maven 命令和设置是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Maven 项目(在管道中),它需要使用在另一个 azure 管道中部署(通过 mvn deploy)的工件作为依赖项.

I have a maven project (in a pipeline) that needs to consume artifacts deployed (via mvn deploy) in another azure pipeline as a dependency.

我可以使用如下命令行将工件上传和下载到 Azure devops:

I am able to upload and download artifacts to Azure devops using command lines like:

az artifacts universal publish 
    --organization https://myorg.visualstudio.com 
    --scope project 
    --project="myproject" 
    --feed myfeed 
    --name someartifact-1.99.1.jar 
    --version 1.99.1 
    --description "snafu" 
    --debug 
    --path .

az artifacts universal download
   --organization "https://myorg.visualstudio.com/"
   --project "myproject"
   --scope project
   --feed "myfeed"   
   --name "someartifact-1.99.1.jar"   --version "1.99.1"
   --path .

等效的 maven 命令应该是这样的:

For which the equivalent maven commands should be something like:

mvn deploy:deploy-file -DWHERE="AzureDevops" clean deploy

mvn -X -B -s maven-azuredevops-settings.xml 
 -DWHERE=AzureDevops
 -DrepoURL=https://myorg.pkgs.visualstudio.com/myproject/_packaging/myfeed/maven/v1   
 dependency:get 
 -Dartifact=com.foobar.blah:someartifact:1.99.1
 -Ddest=./clientartifact.jar

我在 maven-azuredevops-settings.xml 中的位置:

Where I have in my maven-azuredevops-settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <interactiveMode>false</interactiveMode>
  <servers>
    <server>
      <id>feedname</id>
      <username>azureusername</username>
      <password>personal access token</password>
    </server>
  </servers> 
</settings>

同样,我在 pom.xml 中有 Azure 上推荐的设置 - 尽管我没有完全理解它们.

Likewise, I have the settings recommended on Azure in the pom.xml - though I don't fully grok them.

但是我注意到一些差异.当 maven 在管道中部署一个包时,在提要中查看时,Artifact 在它前面有一个大 M for maven.它也被列为:

However I notice some differences. When a package is deployed by maven in a pipeline the Artifact has a big M for maven in front of it when viewed in the feed. It is also listed as:

com.foobar.blah:someartifact 1.9.9

如果直接使用 az artifacts 上传,它是一个普通的通用包,而不是 maven 包.一个关键的区别(它是唯一的吗?)是同一个工件中也有一个 .pom 工件.我的 Maven 构建创建了它并将其放在本地存储库中,但我不清楚如何将它作为同一工件的一部分而不是提要中的单独文件发布.

If uploaded with az artifacts directly it is a plain universal package not a maven package. A key difference (is it the only one?) is that there is a .pom artifact as well in the same artifact. My maven build creates this and puts it in the local repository but I am not clear how to publish it as part of the same artifact rather than a separate file in the feed.

我也遇到了项目范围提要(即 --scope 和 --project)的问题.Maven 报告 401 未经授权,而不是说一个包丢失.尽管已登录,但如果我从命令行获取 repo 的 URL,我会得到 401.这是我目前的主要问题.

I also have trouble with project scoped feeds (i.e. with --scope and --project). Maven reports the 401 unauthorized rather than saying a package is missing. I get a 401 if I wget the URL of the repo from command line despite being logged in. This is my main issue at present.

很明显,我对 Azure 和 Maven 的理解存在一些差距,这两者都是我的新手.有人可以启发我如何让 maven 命令正常工作,或者在可能的情况下使 azure 命令的行为等效.

Clearly there are some gaps in my understanding of both Azure and Maven both of which I am new to. Can someone enlighten me as to how to get the maven commands to work properly or alternatively make the azure commands behave equivalently where that is possible.

对于上下文,我试图通过离线执行等效命令来调试管道.另请参阅 Azure DevOps 管道 - Maven 部署仅在不存在时释放

For context I am trying to debug a pipeline by executing the equivalent commands offline. See also Azure DevOps Pipeline - Maven deploy release only if it does not exist

推荐答案

首先,对于通用包,它只是您上传到我们的服务并标有名称和版本的文件的集合.您可以通过 构建或发布期间的通用包任务.

Firstly, for Universal package, it is just a collection of files that you’ve uploaded to our service and labelled with a name and version. And you can download it through Universal Package task during build or release.

更多信息,可以参考:Universal 入门包

由于您使用的是 JAVA 包,请通过 MVN deploy 部署/发布 JAVA 包.

Since you are using JAVA package, please deploy/publish JAVA package through MVN deploy.

其次,有集合和项目级别/范围提要.对于项目级别/范围,需要在 URL 中指定项目名称,例如 https://pkgs.dev.azure.com/{org}/{project}/_packaging/{feed}/maven/v1.

Secondly, there are collection and project level/scope feeds. For project level/scope, you need to specify project name in URL, such as https://pkgs.dev.azure.com/{org}/{project}/_packaging/{feed}/maven/v1.

第三,要在另一个JAVA项目中使用JAVA包,需要在用户文件夹(${user.home}/.m2)的settings.xml中配置凭证.对于构建或发布管道,您只需要添加 Maven Authenticate 任务 进行身份验证.

Thirdly, to use JAVA package in another JAVA project, you need to configure credential in settings.xml in user's folder (${user.home}/.m2). For build or release pipeline, you just need to add Maven Authenticate task for authentication.

然后,你需要在 pom.xml 中指定 package(在 section 下).您可以在 Connect 中获取此信息以供馈送 >选择 Maven.

Then, you need to specify package in pom.xml (under section). You could get this information in Connect to feed > select Maven.

更多信息,可以参考:开始使用 Maven 提要和工件

这篇关于上传和下载 azure 工件的等效 maven 命令和设置是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆