欢迎访问IT教程网

jenkins+maven+pipeline+docker

Linux admin 681℃ 0评论

1.相关插件配置请参考我的另一篇文章

jenkins+git+maven+docker发布

2.新建任务-选择流水线(英文这里写的是pipeline)

定义两个变量和之前一样

构建触发器,选择轮询

流水线-选择 pipeline script

相关脚本内容如下

node {
 def mvnHome
 stage('Preparation') { // for display purposes
 // git仓库检出
 checkout([$class: 'GitSCM', branches: [[name: '${release_brach}']], 
 userRemoteConfigs: [[url: 'https://github.com/cc0411/firstProject']]])
 // Get the Maven tool.
 // ** NOTE: This 'M3' Maven tool must be configured
 // ** in the global configuration. 
 mvnHome = tool 'mymaven'  //这个是你本地maven的名字,全局系统设置里面你的定义
 }
 stage('Build') {
 // maven构建
 if (isUnix()) {
 sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
 } else {
 bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
 }
 }
 stage('Dev'){
//这一步是执行拷贝并运行脚本部署到docker  采用sshpublish插件
 sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'sh /root/deploy.sh $project_name firstProject $release_brach 30000 8080', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '$project_name', remoteDirectorySDF: false, removePrefix: 'target/', sourceFiles: 'target/*.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
 }
}

本文固定链接:IT教程网 » jenkins+maven+pipeline+docker
本站内容除特别标注外均为原创,欢迎转载,但请保留出处!

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址