Jenkins集成Nexus

demo地址: https://github.com/zeyangli/springboot-helloworld.git

总体目标

开发人员提交代码,更新pom信息。jenkins读取pom文件中的信息,通过nexus插件上传到nexus。通过nexus参数获取最新的包下载地址。

项目配置

pom.xml文件

  • groupId: 业务名称简称
  • artifactId: 应用名称
  • version: 版本信息
  1. <groupId>demo</groupId>
  2. <artifactId>demo-devops-service</artifactId>
  3. <version>4.0</version>

注: 没做一次更新都要更改version信息,因为release的maven仓库设置了不能同版本更新。

Nexus(create repo)

iamges

Jenkins(CI)

  • 安装插件:Pipeline Utility Steps
  • 安装插件:Nexus Artifact Uploader
  • 设置scriptApproval: 允许Approval

iamges

  1. node("master"){
  2. stage("Get Code"){
  3. checkout scm
  4. }
  5. stage("Build & Unit Test"){
  6. def mvnHome="/usr/local/apache-maven-3.6.0"
  7. sh "${mvnHome}/bin/mvn clean install "
  8. }
  9. stage("Scan Code"){
  10. println("code scan")
  11. }
  12. stage("Push Nexus"){
  13. def pom = readMavenPom file: 'pom.xml'
  14. nexusArtifactUploader(artifacts: [[artifactId: "${pom.artifactId}",
  15. classifier: '',
  16. file: "./target/${pom.artifactId}-${pom.version}.${pom.packaging}",
  17. type: "${pom.packaging}"]],
  18. credentialsId: 'nexus-admin',
  19. groupId: "${pom.groupId}",
  20. nexusUrl: '192.168.0.44:8081',
  21. nexusVersion: 'nexus3',
  22. protocol: 'http',
  23. repository: "${pom.groupId}",
  24. version: "${pom.version}")
  25. }
  26. stage("To Email "){
  27. }
  28. }

Jenkins (CD)

  • 安装插件: Maven Artifact ChoiceListProvider (Nexus)

images

images

构建

images