持续集成交付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}")
                }
相关推荐
虎头金猫18 小时前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
AI职业加油站20 小时前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏21 小时前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
-梅21 小时前
linux(8) 软硬链接
linux·运维·服务器
张洛闻Eren1 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github
其实防守也摸鱼1 天前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
布裘1 天前
【银河麒麟】V4桌面图标消失,右击鼠标没反应排查
运维·银河麒麟·桌面环境
懂软件的胡子个哥1 天前
微信机器人为什么需要“回复候选”而不是所有 AI 内容直接发送
运维·微信·自动化·wechatapi·个人微信号二次开发
云贝贝贝1 天前
腾讯云 TDSQL(MySQL 版)性能优化与慢查询排障实战 6 招
运维·腾讯云
Lsetea1 天前
证书没到期却报certificate has expired:OpenSSL定位中间证书与系统时间
运维·https·ssl证书·openssl·证书链