Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline error - Unknown stage section "sh" and steps in a stage must be in a steps block

I had something almost identical to this and it worked fine and now I get the below errors. I have parallel, steps and stages all there.

Error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 23: Unknown stage section "sh". Starting with version 0.5, steps in a stage must be in a steps block. @ line 23, column 7.
         stage('build api image') {
         ^

WorkflowScript: 26: Unknown stage section "sh". Starting with version 0.5, steps in a stage must be in a steps block. @ line 26, column 7.
         stage('build view image') {
         ^

WorkflowScript: 20: No "steps" or "parallel" to execute within stage "gradle test" @ line 20, column 7.
         stage('gradle test') {
         ^

WorkflowScript: 23: No "steps" or "parallel" to execute within stage "build api image" @ line 23, column 7.
         stage('build api image') {
         ^

WorkflowScript: 26: No "steps" or "parallel" to execute within stage "build view image" @ line 26, column 7.
         stage('build view image') {

pipeline {
    agent any

    stages {
      stage('run test cases in modules') {
            steps {
              parallel(
              "Gradle clean": {
                  sh "./gradlew clean"
               },
                "api-service-tests": {
                  sh "./gradlew api:test"
                },
                "cache-api-tests": {
                  sh "./gradlew view:test"
                }
              )
            }
      }
      stage('gradle test') {
            // sh "./gradlew --no-daemon test"
      }
      stage('build api image') {
            sh "oc start-build cms-api --from-dir=api/docker --follow"
      }
      stage('build view image') {
            sh "oc start-build  --from-dir=view --follow"
      }
    }

}
like image 934
Mike3355 Avatar asked Jun 05 '18 14:06

Mike3355


People also ask

What is steps in Jenkins?

Jenkins Pipeline allows you to compose multiple steps in an easy way that can help you model any sort of automation process. Think of a "step" like a single command which performs a single action. When a step succeeds it moves onto the next step. When a step fails to execute correctly the Pipeline will fail.


1 Answers

You are missing the steps directive inside of your other stage directives.

stage('gradle test') {
  // sh "./gradlew --no-daemon test"
}

Should be something more like:

stage('gradle test') {
  steps {
    sh "./gradlew --no-daemon test"
  }
}
like image 74
mkobit Avatar answered Sep 18 '22 16:09

mkobit