Maven、Jenkins、Nexus 的基础设施

发布于 2024-11-27 18:56:51 字数 897 浏览 1 评论 0原文

我们使用的是maven。我想设置基础设施,以便自动构建的工件将进入 Nexus 存储库。然后开发人员就可以使用它们。

我已经为我们的项目设置了 Jenkins 1 个工作。 我将 Nexus 设置在同一台服务器上。

在开发人员的 PC 上,我将默认的 Maven 设置复制到 C:\Users{user}.m2\settings.xml 添加此部分。 参考资料:

配置 Maven 使用单个 Nexus

Maven 设置参考

<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

Maven Settings Reference

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

傲性难收 2024-12-04 18:56:51

要将工件部署到 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 a deploy 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.

書生途 2024-12-04 18:56:51

我不需要对我的项目 pom.xml 进行任何更改。相反,在 jenkins“构建后操作”中,我选择“将工件部署到 Maven 存储库”,然后选择“高级”并将存储库 URL 设置为 http://nexusserver:8081/nexus/content/repositories/releases< /code> 和 deploymentRepo 的存储库 ID。

在 jenkins 机器上的 ~/.m2/settings.xml 中,我添加了

<settings>
  <servers>
    <server>
      <id>deploymentRepo</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>
   ...

</settings>

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 to deploymentRepo.

In the ~/.m2/settings.xml on the jenkins machine I added

<settings>
  <servers>
    <server>
      <id>deploymentRepo</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>
   ...

</settings>
靑春怀旧 2024-12-04 18:56:51

更新pom.xml

 <distributionManagement>
    ...
    <repository>
      <id>deploymentRepo</id>
      <name>Internal Releases</name>
      <url>http://nexusserver:8081/nexus/content/repositories/releases</url>
    </repository>
    ...
  </distributionManagement>

,然后为maven添加~/.m2/settings.xml(这是Nexus中的默认部署用户)

<server>
  <id>deploymentRepo</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>

,然后mvn部署

然后可以在任何项目中使用已部署的工件,就像标准工件一样。
在这种情况下,添加到 pom.xml

<!-- company repositories -->
    <repository>
        <id>deploymentRepoReleases</id>
        <name>Releases (Nexus)</name>
        <url>http://nexusserver:8081/nexus/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>deploymentRepoSnapshots</id>
        <name>Snapshots (Nexus)</name>
        <url>http://nexusserver:8081/nexus/content/repositories/snapshots/</url>
    </repository>

更新:后来我们放弃了快照存储库,并使用仅需要发布类型存储库的 maven-release-plugin

update pom.xml

 <distributionManagement>
    ...
    <repository>
      <id>deploymentRepo</id>
      <name>Internal Releases</name>
      <url>http://nexusserver:8081/nexus/content/repositories/releases</url>
    </repository>
    ...
  </distributionManagement>

then for maven ~/.m2/settings.xml add (this is default deployment user in Nexus)

<server>
  <id>deploymentRepo</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>

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

<!-- company repositories -->
    <repository>
        <id>deploymentRepoReleases</id>
        <name>Releases (Nexus)</name>
        <url>http://nexusserver:8081/nexus/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>deploymentRepoSnapshots</id>
        <name>Snapshots (Nexus)</name>
        <url>http://nexusserver:8081/nexus/content/repositories/snapshots/</url>
    </repository>

UPDATE: Later we went away from Snapshot repositories and were using maven-release-plugin that only needs repositories of release type.

蓝海 2024-12-04 18:56:51

如果这是 Jenkins 问题而不是 Maven 问题,我建议在大多数情况下使用内置 Jenkins“将工件部署到 Maven 存储库”构建后操作。

我认为优点:

  • 更可移植(我们在生命周期的不同阶段使用不同的存储库),每个 Jenkins 实例都知道它自己的存储库
  • 对于任何阅读 Jenkins 作业的人来说都更明显
  • 更符合 Jenkins 的做事方式

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:

  • More portable (we use different repositories for different stages of the life cycle), and each Jenkins instance knows it's own repository
  • More obvious to anyone reading the Jenkins job
  • More in line with the Jenkins way of doing things
寄意 2024-12-04 18:56:51

maven-release-plugin 的以下 Maven 目标参数可用于传递 Nexus 存储库身份验证,

-Dusername=<> -Dpassword=<>

与 jenkins 项目、maven 命令行一起使用,用于 Nexus 存储库身份验证

Following maven goal arguments for the maven-release-plugin can be used to pass the nexus repository authentication

-Dusername=<> -Dpassword=<>

use with jenkins project, maven command line, for nexus repo authentication

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文