croakPedlar
croakPedlar

Reputation: 244

Jenkins Error: "Unknown stage section "stage". Starting with version 0.5, steps in a stage must be in a 'steps' block

Per my header, I'm receiving the following error for my jenkins setup:

Unknown stage section "stage". Starting with version 0.5, steps in a stage must be in a 'steps' block. @line xxx, column xx.
stage('First Parallel Stage') {
^

My configuration:

pipeline {
    stages {
        stage('Header_1'){
            steps{}
        }
        stage('Header_2'){
            steps{}
        }
        parallel{
            stage('First Parallel Stage'){
                environment{}
            }
            stages {
                stage('Another_One'){
                    steps{}
                }
            }
        }
     }
 }

I've tried putting an empty steps{} in stage('First Parallel Stage') and tried putting it inside steps. I'm unsure what could be wrong.

Upvotes: 3

Views: 8566

Answers (1)

crash
crash

Reputation: 670

You'll need to put stages that are grouped together into a stage and parallel must be within a stage too. Full working example:

pipeline {
    agent any

    stages {
        stage('Header_1') {
            steps {
                echo '1'
            }
        }
        stage('Header_2') {
            steps {
                echo '2'
            }
        }
        
        stage('Parallel') { // add this
            parallel {
                stage('First Parallel Stage') {
                    environment {
                        TEST = 3
                    }
                    
                    steps {
                        echo "$TEST"
                    }
                }
                
                stage('Execute this together') { // add this
                    stages {
                        stage('Another_One') {
                            steps {
                                echo "4"
                            }
                        }
                        
                        stage('Yet Another_One') {
                            steps {
                                echo "5"
                            }
                        }
                    }
                }
            }
        }
    }
}

Please note that you can't have parallel{} inside of parallel{}, but you can chain them¹.

On BlueOcean it then looks like the following:

enter image description here

¹: Edit 2023: This answer explains how it is possible through workarounds.

Upvotes: 6

Related Questions