Jenkins pipeline (parallel && dynamically)?

后端 未结 2 1791
傲寒
傲寒 2021-02-09 17:08

Question

I have simple parallel pipeline (see code) which I use together with Jenkins 2.89.2. Additionally I use parameters and now want to be able to in-/decrease the

2条回答
  •  独厮守ぢ
    2021-02-09 17:40

    @Vitalii

    I wrote similiar code piece, but unfoutunelty, all three element been loopped all shows the last one, not sure if it had something to do with groovy / jenkinsfile itself, that some clouse / reference went break with wrong usage

    my purpose is to distribute tasks to specific work nodes

    node_candicates = ["worker-1", "worder-2", "worker-3"]
    
    def jobs = [:]
    for (node_name in node_candidates){
        jobs["run on $node_name"] = {             // good
            stage("run on $node_name"){           // all show the third 
                node(node_name){                  // all show the third 
                    print "on $node_name"
                    sh "hostname"
                }
            }
        }
    }    
    parallel jobs
    

    it went totally Ok if I expand / explain the loop, instead of loop over it, like

    parallel worker_1: {
        stage("worker_1"){
            node("worker_1"){
                sh """hostname ; pwd """
                print "on worker_1"
            }
        }
    },  worker_2: {
        stage("worker_2"){
            node("worker_2"){
                sh """hostname ; pwd """
                print "on worker_2"
            }
        }
    },  worker_3: {
        stage("worker_3"){
            node("worker_3"){
                sh """hostname ; pwd """
                print "on worker_3"
            }
        }
    }
    

提交回复
热议问题