持续集成交付CICD:Jenkins配置Nexus制品上传流水线

目录

一、实验

1.Jenkins配置制品上传流水线

二、问题

1.上传制品显示名称有误


一、实验

1.Jenkins配置制品上传流水线

(1) 新建流水线项目

(2)描述

(3)添加参数

(4)查看构建首页

(5)编辑流水线

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")
                    sh "mvn clean package"
                }
            }

        }

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

        }
        stage("Upload"){
            steps{
                script{
                    NexusUploadByPlugin("${env.artifactId}",
                            "target/maven-test-1.0-SNAPSHOT.jar",
                                        "${env.type}",
                                        "${env.groupId}",
                                        "${env.version}")
                }
            }
        }
    }
}

//NexusUploadByPlugin('devops-test','target/maven-test-1.0-SNAPSHOT.jar','jar','com.jenkins','1.1.2')

def NexusUploadByPlugin(artifactId,file,type,groupId,version ){
    nexusArtifactUploader artifacts: [[artifactId: artifactId,
                                       classifier: '',
                                       file: file,
                                       type: type]],
                          credentialsId: '318df1ad-083b-4158-ac88-2f584446563e',
                          groupId: groupId,
                          nexusUrl: '192.168.204.13:8081',
                          nexusVersion: 'nexus3',
                          protocol: 'http',
                          repository: 'mymavenrepo',
                          version: version
}

(6)开始构建

(7)Blue Ocean查看

(8)查看日志

(9)Nexus查看

二、问题

1.上传制品显示名称有误

(1)报错

(2)原因分析

代码引用错误,使用了单引号

(3)解决方法

修改代码,使用双引号

修改前:

bash 复制代码
script{
                    NexusUploadByPlugin('${env.artifactId}',
                                        'target/maven-test-1.0-SNAPSHOT.jar',
                                        '${env.type}',
                                        '${env.groupId}',
                                        '${env.version}')
                }

修改后:

bash 复制代码
script{
                    NexusUploadByPlugin("${env.artifactId}",
                            "target/maven-test-1.0-SNAPSHOT.jar",
                                        "${env.type}",
                                        "${env.groupId}",
                                        "${env.version}")
                }
相关推荐
feng1456几秒前
稳定性-从端到端观测开始
运维
Tom Ma.12 分钟前
Docker 安装 OpenClaw
运维·docker·容器
姜太小白16 分钟前
【Linux】麒麟V10SP3解决网络设备名不匹配问题
linux·运维·服务器
开开心心_Every16 分钟前
内存清理软件灵活设置,自动阈值快捷键清
运维·服务器·pdf·web3·电脑·excel·共识算法
运维老郭23 分钟前
MySQL 主从延迟根因诊断法:从现象到本质的全链路排查指南
运维·mysql
泛黄的咖啡店28 分钟前
KVM 虚拟化物理机
运维
xcbeyond39 分钟前
Linux 磁盘挂载
linux·运维·服务器
Dontla1 小时前
santifer/career-ops介绍(使用Claude Code自动化搜索招聘岗位并分析)(Playwright、Chromium)
运维·自动化
倔强的胖蚂蚁1 小时前
AI 人工智能配置管理 Nginx
运维·nginx·云原生
上海云盾安全满满1 小时前
服务器如果做好日常维护,有什么作用
运维·服务器