2

我正在使用 Jenkins 2.73.1,我正在尝试使用声明性 Jenkins 文件定义并行阶段,如下所示:

pipeline {
    agent any

    tools {
        jdk 'JDK8'
    }

    options {
        disableConcurrentBuilds()
        timestamps() // write timestamps in front of each console line
    }

    triggers {
        // Every minute
        pollSCM '*/1 * * * *'
    }

    stages {
        stage('Rüsten') {
            steps {
                bat "echo Hello"
            }
        }

        stage('Kochen (parallel)') {

            parallel {
                stage('Salzen') {
                    steps {
                        bat "echo Hello"
                    }        
                }
                stage('Rühren') {
                    steps {
                        bat "echo Hello"
                    }        
                }
                stage('Abschmecken') {
                    steps {
                        bat "echo Hello"
                    }        
                }
            }
        }

        stage('Essen') {
            steps {
                bat "echo Hello"
            }
        }
    }
}

不幸的是,这会导致以下编译错误。

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 25: Unknown stage section "parallel". Starting with version 0.5, steps in a stage must be in a steps block. @ line 25, column 9.
           stage('Kochen (parallel)') {
           ^

WorkflowScript: 25: Nothing to execute within stage "Kochen (parallel)" @ line 25, column 9.
           stage('Kochen (parallel)') {
           ^

2 errors

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:129)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:123)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:517)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:480)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:269)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:419)
Finished: FAILURE

然后我在 Stackoverflow 上找到了以下问题,并尝试应用他们的解决方案,但对我没有任何帮助。

有人可以告诉我是否可以并行运行阶段或步骤,以及如何使用 Jenkins 2.73.1(及更高版本)实现它?

4

1 回答 1

2

该语法是全新的,仅在管道模型定义插件 v 1.2+ 中可用。

如果您想在该版本之前执行此操作,则语法不是很漂亮。

这有一个旧语法的例子:https ://gist.github.com/abayer/925c68132b67254147efd8b86255fd76

于 2017-10-10T15:24:55.650 回答