2

I write this pipeline for run that after push on the develop branch or master branch and doing some workers related to that branch.

I want to check the repository and run pipeline after push on the any branches

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

But it shows me this error:

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

What is the problem?

2
  • 1
    Did you read the error message? Your checkout scm should be inside steps {...}: steps { checkout scm }
    – MaratC
    Mar 8, 2021 at 8:07
  • @MaratC i have a problem with this . when i push in the develop branch it not run the ipline in jenkines i just must push on the maste rbranch for run the projects Mar 8, 2021 at 8:23

1 Answer 1

2

Solution

You need to place checkout scm within a step closure. You also have an additional closing bracket.

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

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.