简体   繁体   English

我可以在 Jenkins 管道中通过普通 Groovy 方法运行并行操作吗?

[英]Can I run parallel actions from a plain Groovy method in my Jenkins pipeline?

My Jenkins pipeline is specified in a declarative way.我的 Jenkins 管道以声明方式指定。 However, in the place I'd like to introduce a parallel step in, I'm forced down into plain Groovy methods:但是,在我想引入并行步骤的地方,我被迫使用普通的 Groovy 方法:

def call(Map parameters) {
    runFirstStep(parameters)
    // add second step that runs in parallel to runFirstStep
}

Unexperienced as I am with Groovy and Jenkins, I hoped to make something simple like this work:由于我对 Groovy 和 Jenkins 没有经验,我希望做一些像这样简单的工作:

def call(Map parameters) {
    parallel(
        'First step': {
            runFirstStep(parameters)
        },
        'Second step': {
            runSecondStep(parameters)
        }
    )
}

However, this seems to mix up declarative and imperative code in an unsuited way and leads to cryptic NullPointerExceptions.但是,这似乎以不合适的方式混合了声明式代码和命令式代码,并导致神秘的 NullPointerExceptions。

Is there another, feasible solution for this?还有其他可行的解决方案吗? Or is overriding the declarative part that surrounds this the only option to squeeze in another parallel step?还是覆盖围绕它的声明部分是挤进另一个并行步骤的唯一选择?

def call(Map parameters) {

    def steps = [:]

    steps['First step'] = {
        node('master') {
            runFirstStep(parameters)
        }
    }

    steps['Second step'] = {
        node('master') {
            runSecondStep(parameters)
        }
    }

    parallel steps.plus([failFast: true])

}

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

相关问题 如何在 jenkins groovy 中并行运行方法 - how to run method in parallel in jenkins groovy 如何在Jenkins管道中并行运行for循环的每个迭代? - How can I run each iteration of a for loop parallel in Jenkins pipeline? 使用管道和常规,如何从Jenkins中提取我当前构建的测试结果? - Using pipeline & groovy, How can I extract test results from Jenkins for my current build? Jenkins Pipeline中的StreamingTemplateEngine与普通Groovy中的StreamingTemplateEngine - StreamingTemplateEngine in Jenkins Pipeline vs. in plain groovy 我如何使用Jenkins并行运行我的集成测试? - How can I use Jenkins to run my integration tests in parallel? 当我的脚本运行的节点是 jenkins 管道脚本时,如何调用 REST API 管道脚本? - How can I call a REST API from jenkins pipeline script when the node my script run is? 在 Jenkins 中并行运行相同的管道 - Run same pipeline in parallel in Jenkins 如何使用Groovy和Kubernetes插件从Jenkins Pipeline运行Kafka? - How to run Kafka from Jenkins Pipeline using Groovy and Kubernetes plugin? 如何隔离我的Jenkins管道Groovy共享库类加载器? - How can I isolate my Jenkins pipeline Groovy shared library classloader? Jenkins Pipeline错误地从常规方法接受多个值 - Jenkins Pipeline errors out accepting multiple values from a groovy method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM