package online.cloud.node def executeRobot = null //声明变量,用于接收遍历list的返回至 def labelList = ["yougou", "beijing", "shanghai", "chengdu", "xianggang"] //定义要遍历的List executeRobot = labelList.collectEntries { //collectEntries 对list的每个元素进行必定格式的迭代转换,返回map ["执行Job ${it}": checkServices(it)] //遍历调用checkServices() } def checkServices(args) { return { //并行执行,须要return,串行执行不须要return /*在scripts里面指定node,至关于另外指定节点机 * 在方法体中能够写非声明式模块代码,扩展性很是强 */ node(args) { stage("${args}") { script { println("当前节点:${args}") } } } } } pipeline { agent { node { label 'master' } } options { disableConcurrentBuilds() //不容许并行执行 timeout(time: 20, unit: 'MINUTES')//设置全局超时时间。 } stages { stage("数据准备") { steps { script { parallel executeRobot //并行执行测试,关键字:parallel;executeRobot变量名 } } } } }