java怎么拦截某个对象
308
2022-09-13
Nexus 07 制品库制品晋级实践
制品晋级实践
制品晋级也需要一条流水线来负责制品的晋级。
准备仓库: 按照环境不同,创建四个仓库分别存储不同环境的包。通过一条单独的流水线完成晋级。
如果包没有问题,可以将这个包晋级到其他仓库当中,步骤就是先下载包,然后传上去。
用户选择:
晋级策略包信息
Jenkinsfile内容:先选晋级策略,然后需要将晋级的包下载下来,然后上传到新的仓库。
获取到制品的信息:
String artifactURL = "${env.artifactUrl}".toString()pipeline { agent any stages { stage('Hello') { steps { script{ println("The artifact url is: ${artifactURL}") env.version = "${params.artifactUrl}".split('/')[-2] env.appName = "${params.artifactUrl}".split('/')[-3] env.buName = "${params.artifactUrl}".split('/')[-4] env.pkgName = env.appName + "-${version}.jar" sh """ echo ${params.artifactUrl} -o ${env.pkgName} -u admin:admin123 """ } } } }}
Started by user adminRunning in Durability level: MAX_SURVIVABILITY[Pipeline] Start of Pipeline[Pipeline] nodeRunning on build-01 in /data/cicd/jenkinsagent/workspace/nexus/nexus-chajian-download[Pipeline] {[Pipeline] stage[Pipeline] { (Hello)[Pipeline] script[Pipeline] {[Pipeline] echoThe artifact url is: sh+ echo -o devops-lib-8.8.8.jar -u admin:admin123-o devops-lib-8.8.8.jar -u admin:admin123[Pipeline] }[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS
完整代码如下:
currentBuild.description = "trigger by ${params.updatePolicy}"pipeline { agent { label "build" } stages{ stage("PullArtifact"){ steps{ script{ env.version = "${params.artifactUrl}".split('/')[-2] env.appName = "${params.artifactUrl}".split('/')[-3] // Day5/acmp-myapp-service env.buName = "${params.artifactUrl}".split('/')[-4] env.pkgName = env.appName + "-${version}.jar" sh """ curl ${params.artifactUrl} -o ${env.pkgName} -u admin:admin123 """ } } } stage("UpdateArtifact"){ steps{ script{ switch("${params.updatePolicy}") { case "dev>uat": repoName = "zeyang-uat" targetDir = "${env.buName}/${env.appName}/${env.version}/" PushRawArtifacts(repoName,targetDir, "./", "${env.pkgName}" ) break; case "uat>stag": repoName = "zeyang-stag" targetDir = "${env.buName}/${env.appName}/${env.version}/" PushRawArtifacts(repoName,targetDir, "./", "${env.pkgName}" ) break; case "stag>prod": repoName = "zeyang-prod" targetDir = "${env.buName}/${env.appName}/${env.version}/" PushRawArtifacts(repoName,targetDir, "./", "${env.pkgName}" ) break; default: println("xxxxxxxxx") } } } } }}//上传制品def PushRawArtifacts(repoName,targetDir, filePath, pkgName ){ withCredentials([usernamePassword(credentialsId: '111b337e-89a0-4761-9ca3-6ee626ccd7a1', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { sh """ curl -X POST "\ -H "accept: application/json" \ -H "Content-Type: multipart/form-data" \ -F "raw.directory=${targetDir}" \ -F "raw.asset1=@${filePath}/${pkgName};type=application/java-archive" \ -F "raw.asset1.filename=${pkgName}" \ -u "${USER}":"${TOKEN}" """ }}
总结:先选择晋级策略,然后下载原始的制品,然后获取到原始的ID信息,然后重命名更改名称,最后上传到制品库就行了。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~