繁体   English   中英

Jenkins 并行声明式管道

[英]Jenkins parallel declarative pipeline

我试图在我的声明性 jenkins 管道中定义一个并行部分。

我基于这个语法: https : //jenkins.io/blog/2017/09/25/declarative-1/

但我收到此错误:

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

我尝试移动并行块,但随后出现其他错误。 据我所知,我匹配上面的博客文章。

有任何想法吗?

版本:

  • 詹金斯版。 2.138.1
  • 管道:声明性版本 1.3.2

我的完整管道如下所示:


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],
                ]
              )

            }
          }

        }
      }
    }
  }
}

您错误地使用了开发博客的“负面”示例:

在早期版本的声明式流水线中,并行运行流水线代码块的唯一方法是使用步骤块内的并行步骤作为一个阶段,如下所示:

虽然这有效,但它不能与声明性管道语法的其余部分很好地集成。

我认为您的问题位于此处:

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

“真实”语法在开发博客中的标记如下:

但是现在在声明式管道 1.2 中,我们为并行运行阶段引入了真正的声明式语法:

这将如下所示(只需从上面删除您的步骤{}):

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