Skip to content

一、Nexus Repository Manager Publisher

官方文档 https://help.sonatype.com/integrations/nexus-and-continuous-integration/nexus-platform-plugin-for-jenkins

1.1 安装Nexus Repository Manager插件

  • 离线下载安装

https://updates.jenkins.io/download/plugins/nexus-jenkins-plugin/3.8.20190920-091853.5b0aa4e/nexus-jenkins-plugin.hpi

Jenkins dashboard, navigate to Manage Jenkins -> Plugin Manager, proceed to the Advanced tab, and upload the downloaded HPI using the Upload Plugin form shown below

上传插件

  • 在线安装

直接搜索 nexus

1.2 配置 jenkins

next thing you need to do is configure a Nexus Repository Manager to be able to upload your build artifacts.

Once again click on the Manage Jenkins link from the dashboard and then the Configure System link.

Under the Sonatype Nexus heading select Nexus Repository Manager 2.x Server or 3.x from the Add Nexus Repository Manager Server dropdown

  • nexus3

配置插件

  • nexus2 ,注意2的地址参数

配置插件

1.3 添加凭证

In this step, we should add a Jenkins Crendential of kind "Username with password" with a valid login to our Nexus instance and let's give it an Id of "nexus-credentials."

密码最好和oss中的密码一样

添加凭证

1.4 Tool Configuration (Optional)

  • Manage Jenkins -> Global Tool Configuration

Configuration

二、配置Nexus Oss

2.1 Create a Hosted Repository in Nexus

  • we are creating a hosted repository named "repository-example"

oss创建

  • Deployment policy: allow redeploy
  • Storage: default.
  • nexus2 配置

oss2创建

2.2 Create a Valid User in Nexus OSS

参考 https://help.sonatype.com/repomanager3/security/users

Nexus OSS

  • nexus2 用户创建

oss2用户创建

案例

nexus3

案例

version 随意定义跟pom没有关系

以xxx.war or xxx.jar 为准

  • 上传到oss效果

上传到oss效果

nexus2

  • 配置jenkins

配置jenkins

  • 配置Jenkins中 nexus2x

配置Jenkins中 nexus2x

  • 创建jenkins maven 项目工程

package -DskipTests=true clean package

创建jenkins maven 项目工程

  • 配置项目工程中nexus manager

配置项目工程中nexus manager

  • 配置Version变量

配置Version变量

效果

channel stopped
Uploading Maven asset with groupId: com.tmrm artifactId: tmrm-message version: $Version To repository: prod-Releases
Successfully Uploaded Maven Assets
Finished: SUCCESS
channel stopped
Uploading Maven asset with groupId: com.tmrm artifactId: tmrm-message version: $Version To repository: prod-Releases
Successfully Uploaded Maven Assets
Finished: SUCCESS
  • 效果图

效果1