我正在尝试在声明性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') {
^
我尝试过移动并行块,但是随后出现其他错误。据我所见,我匹配上面的博客文章。
有任何想法吗?
版本:
我的完整管道如下所示:
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],
]
)
}
}
}
}
}
}
}
你使用开发博客的“负”示例时犯了一个错误:
在早期版本的Declarative Pipeline中,并行运行Pipeline代码块的唯一方法是在步骤的步骤块内使用并行步骤,如下所示:你的示例
尽管此方法有效,但它与其余的“声明性管道”语法无法很好地集成。
我认为你的问题位于此处:
stage('app cores') {
steps { // This step{} is causing the issue, remove it
开发博客中的“真实”语法标记如下:
但是现在在Declarative Pipeline 1.2中,我们为并行运行的阶段引入了一种真正的Declarative语法:
类似于以下内容(只需从上方删除你的步骤{}):
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()之前使用steps()