1

Jenkins pipeline, declarative.

simple question, how do I create a parallel stages inside stage which is parallel by itself?

pipeline {
agent { label 'master' }
options {
    timestamps()
    timeout(time: 15, unit: 'MINUTES')
    ansiColor('xterm')
}

stages {
        stage('Main parallel') {
            parallel {
                stage('Start containers') {
                agent { label 'my-agent' }
                    stages {
                        stage('Start Linux containers') {
                            steps {
                                script {
                                    dir (""){
                                        println "running"
                                    }
                                }   
                            }
                        }

                    }
                }
                stage('Build UI') {
                    stages {
                        stage('Cleanup main workspace'){
                            steps {
                                    dir("") {
                                        cleanWs()
                                    }
                            }
                        }
                        stage('Git checkout') {
                            steps {
                                dir("") {
                                        checkout()
                                }
                            }
                        }

                        stages {
                            stage('Gradle build') {
                                parallel{
                                    stage('gradle1') {
                                        steps {
                                            dir("") {
                                                script {
                                                            buildInfo = rtGradle.run switches: gradleParams , tasks: 'clean deploy'

                                                        }
                                                }
                                            }
                                        }
                                    }
                                    stage('gradle2') {
                                        steps {
                                            dir("") {
                                                script {
                                                        buildInfo2 = rtGradle2.run switches: gradleParams , tasks: 'unitTests'

                                                    }
                                                }
                                            }   
                                        }
                                    }   
                            }
                        }
                }
            }
        }
    }
}

I am sure it is possible, but how?

thanks

1

Sure, you can do this with Scripted Pipelines. I've never tried to do it with Declarative so I'm not sure whether it's possible to do with Declarative or, if it is, if it's easy or straightforward.

Here's an example of what this might look like with a Scripted Pipeline. I haven't tested it so there may be syntax errors or other problems.

def parallelTopLevelSteps = [:]

parallelTopLevelSteps['A and B'] = {
  def parallelNestedSteps = [:]

  parallelNestedSteps['step A'] = { echo('A') }
  parallelNestedSteps['step B'] = { echo('B') }

  parallel(parallelNestedSteps)
}

parallelTopLevelSteps['C and D'] = {
  def parallelNestedSteps = [:]

  parallelNestedSteps['step C'] = { echo('C') }
  parallelNestedSteps['step D'] = { echo('D') }

  parallel(parallelNestedSteps)
}

parallel(parallelTopLevelSteps)
  • need to add stages and steps, but it is the right and elegant way to do it. – amichib Oct 24 '18 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.