2
votes

I'm trying dynamically generate stages to run them parallel, but facing next error:

WorkflowScript: 59: Expected one of "steps", "stages", or "parallel" for stage "main" @ line 59, column 5. stage('main') { ^

Here's the jenkins pipeline:

def tasks = [:]

pipeline {
  agent any
  stages {
    stage('pre') {
      steps {
        script {
            for (cl in env.CLUSTERS.split()) {
              tasks["${cl}"] = {
                stage ("${cl}") {
                  steps {
                    script {
                      sh (script: "./run.sh ${cl}", returnStdout: true)
                    }
                  }
                }
              }
            }
          }
        }
    }
    stage('main') {
      steps {
        parallel tasks
      }
    }
  }
}

Is there a way to fix this?

Thanks

1

1 Answers

0
votes

Your stage('pre') does not seem to be bounded by a closing '}', before the stage('main') starts with its own {.

See if adding one more '}' would help here.