Maven、Jenkins、Nexus 的基础设施
我们使用的是maven。我想设置基础设施,以便自动构建的工件将进入 Nexus 存储库。然后开发人员就可以使用它们。
我已经为我们的项目设置了 Jenkins 1 个工作。 我将 Nexus 设置在同一台服务器上。
在开发人员的 PC 上,我将默认的 Maven 设置复制到 C:\Users{user}.m2\settings.xml 添加此部分。 参考资料:
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://myserver:8081/nexus/content/groups/public</url>
</mirror>
(我只是遵循使用 Nexus 进行存储库管理 书)
我接下来的步骤应该是什么? Jenkins 作业应该有 mvn install
吗? 如何为公司工件创建 Nexus 存储库?
We are using maven. I want to set up infrastructure, so that automatically built artifacts would go to Nexus repository. And then they could be used by developers.
I have already set up Jenkins with 1 job for our project.
And I set up Nexus to on the same server.
On developers' PCs I copied default maven setting to C:\Users{user}.m2\settings.xml
adding this section.
References:
Configuring Maven to Use a Single Nexus
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://myserver:8081/nexus/content/groups/public</url>
</mirror>
(I just follow Repository Management with Nexus book)
What are my next steps should be?
Should Jenkins job have mvn install
?
How to create Nexus repository for company artifacts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要将工件部署到 Nexus,您需要在 pom.xml 中包含 distributionManagement 部分。 Nexus 附带了已为快照和版本设置的特定存储库。您应该为每个路径提供正确的路径,以便 Maven 将部署快照并将工件发布到正确的存储库。然后,每当您部署工件时 - 通常使用
mvn deploy
或使用 maven 发布插件,工件将部署在那里。默认情况下,Nexus 具有写入身份验证功能,因此您需要确保添加具有正确信息的服务器部分将部署工件的任何人的 settings.xml 的凭据。 Jenkins 可以像任何其他用户一样对待。如果您让它进行部署
作为其构建,那么每个构建都会部署到 Nexus。还有一个用于部署工件的构建后操作,以防您希望它稍后在 Jenkins 作业中发生。To deploy artifacts to Nexus, you'll need to include a distributionManagement section in your pom. Nexus ships with specific repositories already set up for both snapshots and releases. You should give the correct path to each of those so that maven will deploy snapshot and release artifacts to the correct repos. Then any time you deploy artifacts--typically with
mvn deploy
or using the maven release plugin, the artifacts will be deployed there. Nexus has write authentication on by default, so you'll need to make sure to add a server section with the correct credentials to the settings.xml of anyone who will be deploying artifacts. Jenkins can be treated pretty much like any other user. If you have it do adeploy
as its build, then every build will deploy to Nexus. There's also a post-build action for deploying artifacts in case you want it to happen later in the Jenkins job.我不需要对我的项目 pom.xml 进行任何更改。相反,在 jenkins“构建后操作”中,我选择“将工件部署到 Maven 存储库”,然后选择“高级”并将存储库 URL 设置为
http://nexusserver:8081/nexus/content/repositories/releases< /code> 和
deploymentRepo
的存储库 ID。在 jenkins 机器上的
~/.m2/settings.xml
中,我添加了I didn't need to make any changes to my projects pom.xml. Instead, in the jenkins "Post-build Actions" I selected "Deploy artifacts to Maven repository" then selected "Advanced" and set the Repository URL to
http://nexusserver:8081/nexus/content/repositories/releases
and the Repository ID todeploymentRepo
.In the
~/.m2/settings.xml
on the jenkins machine I added更新
pom.xml
,然后为maven添加
~/.m2/settings.xml
(这是Nexus中的默认部署用户),然后
mvn部署
然后可以在任何项目中使用已部署的工件,就像标准工件一样。
在这种情况下,添加到 pom.xml
更新:后来我们放弃了快照存储库,并使用仅需要发布类型存储库的
maven-release-plugin
。update
pom.xml
then for maven
~/.m2/settings.xml
add (this is default deployment user in Nexus)then
mvn deploy
Then it is possible to use deployed artifact in any project, just as standard artifacts.
In this case add to pom.xml
UPDATE: Later we went away from Snapshot repositories and were using
maven-release-plugin
that only needs repositories of release type.如果这是 Jenkins 问题而不是 Maven 问题,我建议在大多数情况下使用内置 Jenkins“将工件部署到 Maven 存储库”构建后操作。
我认为优点:
If this is a Jenkins question rather than a Maven question, I'd recommend using the inbuilt Jenkins "Deploy Artifacts to Maven repository" Post build Action for most cases.
Advantages in my opinion:
maven-release-plugin 的以下 Maven 目标参数可用于传递 Nexus 存储库身份验证,
与 jenkins 项目、maven 命令行一起使用,用于 Nexus 存储库身份验证
Following maven goal arguments for the maven-release-plugin can be used to pass the nexus repository authentication
use with jenkins project, maven command line, for nexus repo authentication