持续集成交付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查看

相关推荐
烟雨书信11 分钟前
Docker文件操作、数据卷、挂载
运维·docker·容器
IT成长日记14 分钟前
【Docker基础】Docker数据卷管理:docker volume prune及其参数详解
运维·docker·容器·volume·prune
这儿有一堆花20 分钟前
Docker编译环境搭建与开发实战指南
运维·docker·容器
LuckyLay20 分钟前
Compose 高级用法详解——AI教你学Docker
运维·docker·容器
Uluoyu29 分钟前
redisSearch docker安装
运维·redis·docker·容器
IT成长日记5 小时前
【Docker基础】Docker数据持久化与卷(Volume)介绍
运维·docker·容器·数据持久化·volume·
物联网老王7 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
艾伦_耶格宇8 小时前
【ACP】阿里云云计算高级运维工程师--ACP
运维·阿里云·云计算
一位摩羯座DBA9 小时前
Redhat&Centos挂载镜像
linux·运维·centos
cui_win10 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络