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

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

根据我的 header,我的 jenkins 设置收到以下错误:

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') {
^

我的配置:

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

我试过在 stage('First Parallel Stage') 中放置一个空步骤{},并尝试将它放在步骤中。我不确定哪里出了问题。

您需要将组合在一起的阶段放在一个阶段中,并且并行也必须在一个阶段中。完整的工作示例:

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"
                            }
                        }
                    }
                }
            }
        }
    }
}

请注意,parallel{} 内不能有 parallel{},但可以将它们链接起来。

在 BlueOcean 上它看起来像下面这样: