詹金斯并行声明管道

时间:2019-05-16 17:11:59

标签: jenkins jenkins-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],
                ]
              )

            }
          }

        }
      }
    }
  }
}

2 个答案:

答案 0 :(得分:1)

您使用开发博客的“负”示例时犯了一个错误:

  

在声明性管道的早期版本中,唯一的运行方式   并行的流水线代码块使用并行步骤   在一个阶段的步骤块中,例如:您的示例

     

虽然可行,但无法与其余的   声明性管道语法。

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

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'

答案 1 :(得分:0)

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