码迷,mamicode.com
首页 > 其他好文 > 详细

Jenkins 中如何一次构建多个项目

时间:2018-01-20 18:51:00      阅读:1750      评论:0      收藏:0      [点我收藏+]

标签:++   return   ati   param   copy   orm   启动   基础   into   

如果用Jenkins中的 pipeline 的话,

这个可以用jenkins pipline语法帮忙生成,

1. 同时 build 多个 stage

stage(‘test‘) {
    build job: ‘testPowerShell‘, parameters: [
     [$class: ‘StringParameterValue‘, name: ‘serviceNames‘, value: ‘reveal,TestCert‘],
     [$class: ‘StringParameterValue‘, name: ‘filelocation‘, value: ‘D:\\serverlist.json‘],
     [$class: ‘StringParameterValue‘, name: ‘groupNo‘, value: ‘0‘]
    ]
   }
   stage(‘test2‘) {
    build job: ‘testPowerShell‘, parameters: [
     [$class: ‘StringParameterValue‘, name: ‘serviceNames‘, value: ‘reveal,TestCert‘],
     [$class: ‘StringParameterValue‘, name: ‘filelocation‘, value: ‘D:\\serverlist.json‘],
     [$class: ‘StringParameterValue‘, name: ‘groupNo‘, value: ‘0‘]
    ]
   }

2. 使用 parallel 平行处理

parallel(
   job1:{stage(‘testPowerShell‘) {
    build job: ‘testPowerShell‘, parameters: [
     [$class: ‘StringParameterValue‘, name: ‘serviceNames‘, value: ‘reveal,TestCert‘],
     [$class: ‘StringParameterValue‘, name: ‘filelocation‘, value: ‘D:\\serverlist.json‘],
     [$class: ‘StringParameterValue‘, name: ‘groupNo‘, value: ‘0‘]
    ]
   }}
 ,
  job2:{stage(‘TestCopy‘) {
   build job: ‘TestCopy‘, parameters: [
    [$class: ‘StringParameterValue‘, name: ‘excludeFolders‘, value: ‘D:\\Downloads\\NewReveal\\reveal.js-master\\test D:\\Downloads\\NewReveal\\reveal.js-master\\js‘]
   ]
 }}
)

将多个 stage 视为同一个 node 会同时启动,会等待较长的 stage 完成后才统一返回结果

3. 在同一个 stage build 多个 job

有基础依赖的 job 先完成后再进行其他 job 的建置

只在 stage 2 传入多个 job 并使用 parallel build

def transformIntoStep(jobFullName) {
 return {
  build job: jobFullName,
  parameters: [string(name: ‘Environ‘, value: ‘QA‘)],
  quietPeriod: 3
 }
}


stage(‘Step1‘) {
 build job: ‘A01-TestDev‘, parameters: [
  [$class: ‘StringParameterValue‘, name: ‘serviceNames‘, value: ‘reveal,TestCert‘],
  [$class: ‘StringParameterValue‘, name: ‘filelocation‘, value: ‘D:\\serverlist.json‘],
  [$class: ‘StringParameterValue‘, name: ‘groupNo‘, value: ‘0‘]
 ]
}
stage(‘Step2‘) {
 def branches = [: ]
 def jobs = "${buildjobs}".tokenize(‘,‘)
 def i = 0;
 for (jobName in jobs) {
  //println(jobName);
  branches["job${i}"] = transformIntoStep(jobName);
  i++;
 }
 //println(branches);
 parallel branches;

}
stage(‘Step3‘) {
 build job: ‘A01-TestDev‘, parameters: [
  [$class: ‘StringParameterValue‘, name: ‘serviceNames‘, value: ‘reveal,TestCert‘],
  [$class: ‘StringParameterValue‘, name: ‘filelocation‘, value: ‘D:\\serverlist.json‘],
  [$class: ‘StringParameterValue‘, name: ‘groupNo‘, value: ‘0‘]
 ]
}

Jenkins 中如何一次构建多个项目

标签:++   return   ati   param   copy   orm   启动   基础   into   

原文地址:https://www.cnblogs.com/flyhgx/p/8321341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!