临时詹金斯管道的现场注释

我最近遇到了挑战。 我已经编写了PR来改进开源库,但是该库的所有者尚未合并它。 我真的不想等到他们合并库之后再使用它,所以我需要将其副本(具有修改的版本ID)部署到私有工件服务器上。

我无法修改回购以拥有Jenkinsfile的事实,以及我要使用自己的即兴版本进行构建时要尝试执行的操作,需要一些仔细的脚本编写。 解决方案是使用临时的管道作为Jenkins中的纯管道构建。

您可以编写这样的任意强大脚本并仅在Jenkins框中运行它的事实足以证明您应确保它们的安全!

 // define the server instance via it's name and  // the artifactory plugin  def server = Artifactory.server "artifactory_prod"  server.credentialsId = 'artifactory-apitoken'  pipeline { 
     environment { 
         buildInfo = null 
     }     
     agent any 
     stages { 
         // A pure pipeline build needs to be told how to check out 
         stage ( 'Checkout' ) { 
             steps { 
                 // the feature branch I hope be merged to an official release 
                 // and the link to my github repo 
                 git branch: 'batch_uses_s3' , 
                     url: ' https://github.com/ashleyfrieze/amazon-sqs-java-extended-client-lib ' url: ' https://github.com/ashleyfrieze/amazon-sqs-java-extended-client-lib ' 
             } 
         } 
         stage ( 'Rewrite version' ) { 
             steps { 
                 script { 
                     // the version of the pom file from git is not under our control 
                     // so modify it to disambiguate from the _real_ version 
                     def descriptor = Artifactory.mavenDescriptor() 
                     descriptor.version = '1.0.2f' 
                     descriptor.transform() 
                 } 
             } 
         } 
         stage ( 'Build' ) { 
             steps { 
                 script { 
                     def rtMaven = Artifactory.newMavenBuild() 
                     // Set Maven build tool 
                     rtMaven.tool = 'maven-3-6-1' 
                     // the artifactory virtual repos for resolving 
                     // dependencies 
                     rtMaven.resolver ( 
                         server: server, 
                         releaseRepo: 'libs-release' , 
                         snapshotRepo: 'libs-snapshot' 
                     ) 
                     // the run command in a moment is going to build 
                     // then deploy - we need to set the target server 
                     // and repo to use 
                     rtMaven.deployer ( 
                         server: server, 
                         releaseRepo: 'internal-release' 
                     )                     
                     // do the build - though this doesn't include deploy 
                     // the artifactory plugin will do the deploy for us 
                     buildInfo = rtMaven.run ( 
                         pom: 'pom.xml' , 
                         goals: 'clean install' , 
                     ) 
                 }                 
                 junit 'target/surefire-reports/*.xml' 
             } 
         }         
     }  } 

那里有些可复制的花絮……但这就是问题。 这不是使用Maven的好方法。 人工制品的作者似乎已经对自己的产品不知所措,并认为它是构建的中心……这很奇怪。

必须将maven的执行交给工件来为您运行,这毫无意义。 这在这里有所帮助,因为它可以覆盖此特定回购的Maven构建的pom文件中缺少本地工件的情况,但这是一种有趣的方法。 Maven允许您通过pom或命令行控制其对人工制品的使用。 通过插件来做到这一点似乎很紧密,我很确定它为您提供了更少的配置选项,而不是更多。

但是,它的确使您知道如何在maven命令行中设置正确的值。

翻译自: https://www.javacodegeeks.com/2019/09/field-notes-from-an-ad-hoc-jenkins-pipeline.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值