juzzlin
juzzlin

Reputation: 47945

Jenkins Pipelines: How to run one stage parallel to many?

I'd like to run one stage parallel to two stages and all this after three other stages.

Something like this (not valid syntax as-is):

pipeline {
    stages {
        stage('Build A') {
        }
        stage('Build B') {
        }
        stage('Build C') {
        }
        parallel {
            stages {
                stage('Build D1') {
                }
                stage('Build D2') {
                }
            }
            stage('Build D3') {
            }
        } 
    }
}

Is it possible to arrange this kind of a structure?

Upvotes: 1

Views: 924

Answers (1)

hakamairi
hakamairi

Reputation: 4678

The way to do that are sequential stages in parallel.

pipeline {
    agent none

    stages {
        stage("build and deploy on Windows and Linux") {
            parallel {
                stage("windows") {
                    agent {
                        label "windows"
                    }
                    stages {
                        stage("build") {
                            steps {
                                bat "run-build.bat"
                            }
                        }
                        stage("deploy") {
                            when {
                                branch "master"
                            }
                            steps {
                                bat "run-deploy.bat"
                            }
                        }
                    }
                }

                stage("linux") {
                    agent {
                        label "linux"
                    }
                    stages {
                        stage("build") {
                            steps {
                                sh "./run-build.sh"
                            }
                        }
                        stage("deploy") {
                             when {
                                 branch "master"
                             }
                             steps {
                                sh "./run-deploy.sh"
                            }
                        }
                    }
                }
            }
        }
    }
}

Upvotes: 3

Related Questions