简体   繁体   English

Jenkins 并行声明式管道

[英]Jenkins parallel declarative pipeline

I'm trying to define a parallel section in my declarative jenkins pipeline.我试图在我的声明性 jenkins 管道中定义一个并行部分。

I'm basing the syntax of this: https://jenkins.io/blog/2017/09/25/declarative-1/我基于这个语法: 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 2.138.1
  • Pipeline: Declarative version 1.3.2管道:声明性版本 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],
                ]
              )

            }
          }

        }
      }
    }
  }
}

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:但是现在在声明式管道 1.2 中,我们为并行运行阶段引入了真正的声明式语法:

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'

这听起来可能很愚蠢,但正如我今天发现的那样, parallel一词中的拼写错误也会引发此异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM