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

相关推荐
OCR_1337162127513 分钟前
技术解析:护照OCR查验核心逻辑,跨境身份核验的技术实现路径
大数据·运维·人工智能
yulingfeng5916 分钟前
Elasticsearch 分词器安装(IK+拼音)
大数据·elasticsearch·jenkins
CQU_JIAKE24 分钟前
5.7[Q]
linux·运维·服务器
wanhengidc30 分钟前
算力服务器的应用场景
运维·服务器·人工智能·安全·web安全·智能手机
Harvy_没救了34 分钟前
【容器技术-Docker】Docker镜像
运维·docker·容器
飞飞传输38 分钟前
内外网文件交换系统产品推荐:高密网低密网摆渡更安全高效
大数据·运维·安全
Cory.眼39 分钟前
AI写CI/CD脚本:Gemini实战指南
ci/cd
Waay41 分钟前
Linux Shell 知识点考评(二):sed 流编辑器(附答案)
linux·运维·服务器
brevity_souls43 分钟前
SQL server格式化日期
运维·服务器·数据库
大肥羊学校懒羊羊1 小时前
FAST-LIVO2 一键复现教程(Ubuntu 20.04 / ROS Noetic )
linux·运维·ubuntu