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

2023-12-15 21:40:49

目录

一、实验

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

二、问题

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


一、实验

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

(1) 新建流水线项目b95661b53c22449da70e2ef407c117c1.png


(2)描述

b8a3fd6a6b1d4dcf99064f699670d031.png(3)添加参数227270a5c1ef434b8f1c3e8d35a0b088.png2208d4a7df7c4939ae812fd017c15492.png

0a71e994991d4239a44a6d505343ba41.pngd9b340a018aa4f2795d0a325694f288b.png961f9fa8089a4dbeb8b2276361af1f75.pngc4c1b158eaaf4e3ba857fb0ca3a8b873.png

(4)查看构建首页

a13d11564047419caeba3da6983da5ef.png

(5)编辑流水线

@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
}

d363fd9a6878442a9147dc7912e1ab66.png

(6)开始构建

(7)Blue Ocean查看

(8)查看日志

(9)Nexus查看

二、问题

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

(1)报错

8f70ea13516645da87e60abfe5645ecd.png

(2)原因分析

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

(3)解决方法

修改代码,使用双引号

修改前:

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

修改后:

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

文章来源:https://blog.csdn.net/cronaldo91/article/details/134892468
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。