持续集成交付CICD:使用Jenkins插件上传Nexus制品

目录

一、实验

1.使用Jenkins插件上传Nexus制品


一、实验

1.使用Jenkins插件上传Nexus制品

(1)Jenkins安装插件Nexus Artifact Uploader

(2)添加凭据

(3)使用片段生成器生成DSL

(4)生成流水线脚本

bash 复制代码
nexusArtifactUploader artifacts: [[artifactId: 'devopstest', classifier: '', file: 'target/maven-test-1.0-SNAPSHOT.jar', type: 'jar']],
credentialsId: '318df1ad-083b-4158-ac88-2f584446563e',
groupId: 'com.jenkins',
nexusUrl: '192.168.204.13:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: 'mymavenrepo',
version: '1.1.2'

(5)Jenkins流水线直接修改回放,点击运行

bash 复制代码
@Library("mylib@master") _
import org.devops.*


def checkout = new Checkout()
def build = new Build()
def unittest = new UnitTest()
def sonar = new Sonar()

pipeline {
    agent { label "build"}

    options {
      skipDefaultCheckout true
    }
    stages{
        stage("Checkout"){
            steps{
                script {
                    println("GetCode")
                    checkout.GetCode("${env.srcUrl}","${env.branchName}")
                }
            }
        }
        stage("build"){
            steps{
                script{
                    println("Build")
                    build.CodeBuild("${env.buildTool}")
                }
            }

        }

        stage("UnitTest"){
            steps{
                script{
                    println("Test")
                    unittest.CodeTest("${env.buildTool}")
                }
            }

        }
        stage("SonarScan"){
            steps {
               script {
                    groupName = "${JOB_NAME}".split("/")[0]
                    projectName ="${JOB_NAME}".split("/")[-1]
                    sonar.CodeSonar("${env.buildTool}",projectName,groupName)
                    
                    nexusArtifactUploader artifacts: [[artifactId: 'devopstest', classifier: '', file: 'target/maven-test-1.0-SNAPSHOT.jar', type: 'jar']], 
                                          credentialsId: '318df1ad-083b-4158-ac88-2f584446563e', 
                                          groupId: 'com.jenkins', 
                                          nexusUrl: '192.168.204.13:8081', 
                                          nexusVersion: 'nexus3', 
                                          protocol: 'http', 
                                          repository: 'mymavenrepo', 
                                          version: '1.1.2'
                }

            }

        }

    }

}

(6)Blue Ocean查看

(7)查看日志,显示已成功上传制品

(8)Nexus查看

相关推荐
DrugOne15 小时前
Amber24 安装指南:Ubuntu 22.04 + CUDA 12.4 环境
linux·运维·ubuntu·drugone
洋葱圈儿66615 小时前
第八个实验——浮动路由
运维·服务器·网络
荣光波比16 小时前
RabbitMQ高可用集群搭建教程(基于CentOS 7.9 + Erlang 23.2.7 + RabbitMQ 3.8.8)
运维·centos·rabbitmq·erlang
zxsz_com_cn16 小时前
基于AI的设备健康诊断:工业设备智能运维的破局之钥
运维·人工智能
de之梦-御风18 小时前
【Linux】 开启关闭MediaMTX服务
linux·运维·服务器
IT 小阿姨(数据库)19 小时前
PostgreSQL通过pg_basebackup物理备份搭建流复制备库(Streaming Replication Standby)
运维·服务器·数据库·sql·postgresql·centos
旗讯数字20 小时前
企业OCR实战:基于OCR技术实现双节差旅报销单表格解析与文字信息自动化采集
运维·自动化·ocr·表格识别
bst@微胖子20 小时前
Harmony中EventHub实现发布订阅
linux·运维·ubuntu
毕业设计论文21 小时前
个人备忘录的设计与实现
运维·服务器·网络
Justin_191 天前
nginx反向代理与缓存功能
运维·nginx