持续集成交付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}")
                }
相关推荐
Dragon~Snow1 小时前
Linux Centos9 安装 Elasticsearch
linux·elasticsearch·jenkins
熊延1 小时前
麒麟V10系统安装部署elasticsearch
linux·运维·服务器·elasticsearch·搜索引擎·全文检索
Yeats_Liao4 小时前
评估体系构建:基于自动化指标与人工打分的双重验证
运维·人工智能·深度学习·算法·机器学习·自动化
爱吃生蚝的于勒4 小时前
【Linux】进程信号之捕捉(三)
linux·运维·服务器·c语言·数据结构·c++·学习
文艺理科生Owen5 小时前
Nginx 路径映射深度解析:从本地开发到生产交付的底层哲学
运维·nginx
期待のcode5 小时前
Redis的主从复制与集群
运维·服务器·redis
wangjialelele6 小时前
Linux下的IO操作以及ext系列文件系统
linux·运维·服务器·c语言·c++·个人开发
HypoxiaDream6 小时前
LINUX-Ext系列⽂件系统
linux·运维·服务器
小毛驴8506 小时前
Linux curl 命令用法
linux·运维·chrome
李斯啦果7 小时前
【Linux】Linux目录配置
linux·运维·服务器