目錄
一、實驗
1.Jenkins配置制品上傳流水線
二、問題
1.上傳制品顯示名稱有誤
?
一、實驗
1.Jenkins配置制品上傳流水線
(1) 新建流水線項目
(2)描述
(3)添加參數
(4)查看構建首頁
(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
}
(6)開始構建
(7)Blue Ocean查看
(8)查看日志
(9)Nexus查看
?
二、問題
1.上傳制品顯示名稱有誤
(1)報錯
(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}")}
?
?