Warm tip: This article is reproduced from serverfault.com, please click

Jenkins parallel declarative pipeline

发布于 2019-05-16 17:11:58

I'm trying to define a parallel section in my declarative jenkins pipeline.

I'm basing the syntax of this: https://jenkins.io/blog/2017/09/25/declarative-1/

But I get this error:

WorkflowScript: 74: Expected one of "steps", "stages", or "parallel" for stage "app cores" @ line 74, column 3.
     stage('bat cores') {
     ^

I've tried moving the parallel block around, but then I get other errors. As far as I can see I match the blog post above.

Any ideas?

Versions:

  • Jenkins ver. 2.138.1
  • Pipeline: Declarative version 1.3.2

My full pipeline looks like this:


pipeline {
  agent { label 'master' }
  options {
    ansiColor('xterm')
  }
  parameters {
    choice(name: 'STOP_ON_FIRST_FAILURE', choices: ['true', 'false'], description: '....')
    choice(name: 'RUN_MODE', choices: [
      'plan, confirm, apply',
      'plan, confirm, apply, then destroy',
      'destroy'],
      description: "Choose to destroy resources at end" )
    string(name: 'GIT_REPO_BRANCH', defaultValue: 'production', description: '...')
  }
  stages {
    stage('thing container') {
      steps {
        build job: '/DevWork/DT/production branch/FA1/FA1 thing Creation', propagate: params.STOP_ON_FIRST_FAILURE
      }
    }

    stage('bat cores') {
      steps {

        build(
          job: '/DevWork/DT/production branch/FA1/FA1 thing Creation',
          propagate: params.STOP_ON_FIRST_FAILURE,
          parameters: [
            [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
            [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
          ]
        )

        build(
          job: '/DevWork/DT/production branch/FA1/FA103/FA103 bat Core',
          propagate: params.STOP_ON_FIRST_FAILURE,
          parameters: [
            [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
            [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
          ]
        )

        build(
          job: '/DevWork/DT/production branch/FA1/FA104/FA104 bat Core',
          propagate: params.STOP_ON_FIRST_FAILURE,
          parameters: [
            [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
            [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
          ]
        )

        build(
          job: '/DevWork/DT/production branch/FA1/FA101/FA101 bat Core',
          propagate: params.STOP_ON_FIRST_FAILURE,
          parameters: [
            [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
            [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
          ]
        )

        build(
          job: '/DevWork/DT/production branch/FA1/FA102/FA102 bat Core',
          propagate: params.STOP_ON_FIRST_FAILURE,
          parameters: [
            [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
            [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
          ]
        )

      }
    }

    stage('app cores') {
      steps {
        parallel {

          stage('FA10302 Application Core') {
            steps {

              build(
                job: '/DevWork/DT/production branch/FA1/FA103/FA10302 Application Core',
                propagate: params.STOP_ON_FIRST_FAILURE,
                parameters: [
                  [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
                  [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
                ]
              )

            }
          }

          stage('FA10301 Application Core') {
            steps {

              build(
                job: '/DevWork/DT/production branch/FA1/FA103/FA10301 Application Core',
                propagate: params.STOP_ON_FIRST_FAILURE,
                parameters: [
                  [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
                  [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
                ]
              )

            }
          }

          stage('FA10101 Application Core') {
            steps {

              build(
                job: '/DevWork/DT/production branch/FA1/FA101/FA10101 Application Core',
                propagate: params.STOP_ON_FIRST_FAILURE,
                parameters: [
                  [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
                  [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
                ]
              )

            }
          }

        }
      }
    }
  }
}

Questioner
David Roussel
Viewed
0
Michael Kemmerzell 2019-05-17 03:40:18

You made the mistake to use the "negative" example of the development blog:

In earlier versions of Declarative Pipeline, the only way to run chunks of Pipeline code in parallel was to use the parallel step inside the steps block for a stage, like this: YOUR EXAMPLE

While this works, it doesn’t integrate well with the rest of the Declarative Pipeline syntax.

I think your issue is located here:

stage('app cores') {
      steps { // This step{} is causing the issue, remove it

The "real" syntax is labeled like the following in the development blog:

But now with Declarative Pipeline 1.2, we’ve introduced a true Declarative syntax for running stages in parallel:

This would look like the following (simply remove your steps{} from above):

stage('app cores') 
{
    parallel {
      stage('FA10302 Application Core') {
        steps {

          build(
            job: '/DevWork/DT/production branch/FA1/FA103/FA10302 Application Core',
            propagate: params.STOP_ON_FIRST_FAILURE,
            parameters: [
              [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
              [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
            ]
          )

        }
      }

      stage('FA10301 Application Core') {
        steps {

          build(
            job: '/DevWork/DT/production branch/FA1/FA103/FA10301 Application Core',
            propagate: params.STOP_ON_FIRST_FAILURE,
            parameters: [
              [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
              [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
            ]
          )

        }
      }

      stage('FA10101 Application Core') {
        steps {

          build(
            job: '/DevWork/DT/production branch/FA1/FA101/FA10101 Application Core',
            propagate: params.STOP_ON_FIRST_FAILURE,
            parameters: [
              [$class: 'StringParameterValue', name: 'RUN_MODE', value: params.RUN_MODE],
              [$class: 'StringParameterValue', name: 'GIT_REPO_BRANCH', value: params.GIT_REPO_BRANCH],
            ]
          )
        }
      }
    } // close the stage 'app cores'