错误 WorkflowScript:8:当需要 运行 管道时,阶段 "check out scm" 的预期 "steps"、"stages" 或 "parallel" 之一

error WorkflowScript: 8: Expected one of "steps", "stages", or "parallel" for stage "check out scm" when need to run pipline

我为 运行 编写了这条管道,在推动 develop 分支或 master banch 并做了一些与那个 barnch 相关的工作之后。

我想在推送任何分支后检查存储库和 运行 管道

pipeline {
    triggers {
        pollSCM('*/1 * * * * ')
    }
    agent any
    stages {
        stage('check out scm') {
             when {
                branch 'master'
            }
            checkout scm
        }
        stage('Install  npm') {
            steps {
                sh 'npm install'
            }
            }
        }
        stage('Build Project Develop') {
            when {
                branch 'develop'
            }
            steps {
                sh 'ng build --prod '
            }
        }
        stage('Build Project Realase')
        {
            when {
                branch 'master'
            }
            steps {
                sh 'ng build --prod '
            }
        }
        stage('Move to Var') {
            steps {
                sh 'chown -R root:jenkins /var/lib/jenkins/workspace/Angular-CI-CD--Test_master/dist/ang-CICD/. && /var/www/html'
            }
        }
    }
}

但它向我显示此错误:

Branch indexing

Connecting to https://api.github.com using kiadr9372/****** (GitHub Access Token)

Obtained Jenkinsfile from d57840a79c46a88969381cc978f378c7d6804cec

Running in Durability level: MAX_SURVIVABILITY



GitHub has been notified of this commit’s build result



org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

WorkflowScript: 8: Unknown stage section "checkout". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 8, column 9.

           stage('check out scm') {

           ^



WorkflowScript: 8: Expected one of "steps", "stages", or "parallel" for stage "check out scm" @ line 8, column 9.

           stage('check out scm') {

           ^

有什么问题吗?我该如何解决这个问题???

解决方案

您需要将 checkout scm 放在步骤闭包中。您还有一个额外的右括号。

pipeline {
    triggers {
        pollSCM('*/1 * * * * ')
    }
    agent any
    stages {
        stage('check out scm') {
             when {
                branch 'master'
            }
            steps {
                checkout scm
            }
        }
        stage('Install  npm') {
            steps {
                sh 'npm install'
            }
        }
        stage('Build Project Develop') {
            when {
                branch 'develop'
            }
            steps {
                sh 'ng build --prod '
            }
        }
        stage('Build Project Realase') {
            when {
                branch 'master'
            }
            steps {
                sh 'ng build --prod '
            }
        }
        stage('Move to Var') {
            steps {
                sh 'chown -R root:jenkins /var/lib/jenkins/workspace/Angular-CI-CD--Test_master/dist/ang-CICD/. && /var/www/html'
            }
        }
    }
}