并行运行多个构建触发器时,只会触发一个构建管道的调用

时间:2020-02-26 12:02:08

标签: jenkins jenkins-pipeline jenkins-groovy

我有两个管道-CallingPipelineCalledPipelineCallingPipeline个呼叫CalledPipeline-

CallingPipeline代码是-

pipeline {
    agent any

    stages {
        stage('Parallel-Run') {
            parallel {
                stage("VM1"){
                    steps {
                        echo "In parent VM1"
                    build job: 'CalledPipeline', parameters: [string(name: 'VMName', value:"VM1")]
                    }
                }
                stage("VM2"){
                    steps {
                        echo "In parent VM2"
                    build job: 'CalledPipeline', parameters: [string(name: 'VMName', value:"VM2")]
                    }
                }
                stage("VM3"){
                    steps {
                        echo "In parent VM3"
                    build job: 'CalledPipeline', parameters: [string(name: 'VMName', value:"VM3")]
                    }
                }
            }
        }
    }
}

CalledPipeline具有构建参数VMName,以下是其代码-

pipeline {
    agent any

    stages {
        stage('Stage-I') {
            steps {
                echo "VMName is " + VMName
                echo "Executing Stage-I"
            }
        }
        stage('Stage-II') {
            steps {
                echo "VMName is " + VMName
                echo "Executing Stage-II"
            }
        }
        stage('Stage-III') {
            steps {
                echo "VMName is " + VMName
                echo "Executing Stage-III"
            }
        }
    }
  }

我运行CallingPipeline时,可以看到其中的每个阶段都是并行执行的,即调度CalledPipeline,但最后只触发了CalledPipeline的一个构建,而不是三。 CallingPipeline的控制台输出为-

In parent VM1
[Pipeline] build (Building CalledPipeline)
Scheduling project: CalledPipeline
[Pipeline] echo
In parent VM2
[Pipeline] build (Building CalledPipeline)
Scheduling project: CalledPipeline
[Pipeline] echo
In parent VM3
[Pipeline] build (Building CalledPipeline)
Scheduling project: CalledPipeline
Starting building: CalledPipeline #5
Starting building: CalledPipeline #5
Starting building: CalledPipeline #5
[Pipeline] }
[Pipeline] }

您能否建议一种有效的方法,以便在CalledPipeline阶段不使用睡眠的情况下为CallingPipeline触发三个构建?

0 个答案:

没有答案