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

 

parallel steps:

 

parallel stage
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
                    }
                }
            }
        }
    }
}
View Code

 

http://www.lujun.org.cn/?p=4025

parallel stage

上一篇:Android 仿京东分类页面功能


下一篇:指针函数