anonymite
anonymite

Reputation: 165

Adding multiple stages in a step in Jenkins Pipeline

I'm trying to get a pipeline that would have 2 steps running in parallel where the YAML looks like:

      steps:
        - step: Step1
          stages:
            - stage: Build
              steps:
                - *build_a
                - *build_b
                - *build_c
            - stage: Sniff
              steps:
                - *sniff
            - stage: Accept
              steps:
                - *regress
                - *test_suite_a
        - *slow_build_that_can_run_in_parallel_to_all_the_above

But Jenkins just passes with the above without running anything. So, I also tried putting everything above in a stage and the slow_build_* ran but Step1 failed to run since it tried to submit the whole step as a batch instead of breaking it into stages.

Is it possible in Jenkins to get multiple stages inside of a step? Or am I doing this wrong?

Upvotes: 3

Views: 20246

Answers (2)

Arnaud Claudel
Arnaud Claudel

Reputation: 3138

No you can't have stages in a step

This is from the Pipeline syntax doc.

  • Stages: Only once, inside the pipeline block

  • Stage: Inside the stages section

  • Steps: Inside each stage block

Upvotes: 8

LemonGo
LemonGo

Reputation: 143

Here's what you can do:

pipeline {
    stages {
        stage('This is a Level 1 Stage') {
            stages {
                stage(This is a level 2 stage') { steps{...} }
                stage(This is a level 2 stage') { steps{...} }
                stage(This is a level 2 stage') { steps{...} }
            }
        }
        stage('This is a Level 1 Stage') {
            stages {
                stage(This is a level 2 stage') { steps{...} }
                stage(This is a level 2 stage') { steps{...} }
                stage(This is a level 2 stage') { steps{...} }
            }
        }
    }
}

Since Jenkins are now allowing nested stages, you can put a stages into a stage to make nested level of stages.

Upvotes: 13

Related Questions