parallel stage
declarative:
pipeline { agent any pipeline { agent any stages { stage('Non-Parallel Stage') { steps { echo 'This stage will be executed first.' } } stage('Parallel Stage') { failFast true parallel { stage('并行一') { steps { echo "并行一" } } stage('并行二') { steps { echo "并行二" } } stage('并行三') { stages { stage('Nested 1') { steps { echo "In stage Nested 1 within Branch C" } } stage('Nested 2') { steps { echo "In stage Nested 2 within Branch C" } } } } } } } }
https://blog.csdn.net/u011541946/article/details/83627600
scripted parallel stages:
https://stackoverflow.com/questions/46834998/scripted-jenkinsfile-parallel-stage
node('docker') { stage('unit test') { parallel([ hello: { echo "hello" }, world: { echo "world" } ]) } stage('build') { def stages = [:] stages["mac"] = { echo "build for mac" } stages["linux"] = { echo "build for linux" } parallel(stages) } }
parallel steps:
pipeline { agent any stages { stage("parallel test") { steps { script { def branches = [:] MAX_CONCURRENT = 2 //创建fifo latch = new java.util.concurrent.LinkedBlockingDeque(MAX_CONCURRENT) //往fifo中,填入最大个数元素 for(int i=0; i<MAX_CONCURRENT; i++) latch.offer("$i") def job_list = [ "test1", "test2", "test3", "test4", "test5", "test6" ] for(int i=0; i<job_list.size(); i++) { def name = job_list[i] branches[name] = { def thing = null waitUntil { //获取一个资源 thing = latch.pollFirst(); return thing != null; } try { //执行job build(job: name, propagate: false) } finally { //释放一个资源 latch.offer(thing) } } } timestamps { parallel branches } } } } } }
http://www.lujun.org.cn/?p=4025
https://stackoverflow.com/questions/46834998/scripted-jenkinsfile-parallel-stage
pipeline { agent {node {label "worker"}} stages { stage('Hello') { steps { script { def stages = [:] py_env_list = ["3.6", "3.7"] OS_VERSION="7.8" image = docker.image("test-centos:test-latest") //image.pull() image.withRun("--name test_ -it --privileged -v ${env.WORKSPACE}:/opt/workspace") { c-> sh """ docker exec ${c.id} bash -c '''echo 1 echo 2 echo $OS_VERSION echo \$SHELL hostname ''' """ } } } } } }
pipeline {
agent {node {label "231_build_worker"}}
stages {
stage('Hello') {
steps {
script {
def stages = [:]
py_env_list = ["3.6", "3.7"]
OS_VERSION="7.8"
image = docker.image("10.150.9.98/sw_test/corex-centos:package-builder-7.8-latest")
//image.pull()
image.withRun("--name test_build_sw_home -it -v /root/.ssh:/root/.ssh -v /dev:/dev -v /usr/src/:/usr/src -v /lib/modules/:/lib/modules --privileged --cap-add=ALL -v ${env.WORKSPACE}:/opt/workspace") { c->
sh """
docker exec ${c.id} bash -c '''echo 1
echo 2
echo $OS_VERSION
echo \$SHELL
hostname
'''
"""
}
}
}
}
}
}