Jenkins 管道与并行 [英] Jenkins pipeline with parallel

查看:19
本文介绍了Jenkins 管道与并行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在尝试执行的 Jenkins 管道.我正在关注

为了让你的 Stages Parallel 使用这个,两种解决方案在 Blue Ocean 中都非常相似:

 管道 {代理任何阶段{阶段('示例阶段'){平行线 {阶段(第一阶段"){步骤 { sh 'echo 阶段 1 已通过' }}阶段(第 2 阶段"){步骤 { sh 'echo 阶段 2 已通过' }}阶段(第 3 阶段"){步骤 { sh 'echo 阶段 3 已通过' }}}}}}

Here is my Jenkins pipeline that i am trying to execute. I am following this tutorial:

pipeline {
    agent any
    stages {
        stage('one') {
            parallel "first" : {               
                    echo "hello"                
            },
            "second": {                
                    echo "world"            
            }
        }
        stage('two') {
            parallel "first" : {               
                    echo "hello"                
            },
            "second": {                
                    echo "world"            
            }
        }
    }
}

But the job fails with following message.

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

WorkflowScript: 12: Unknown stage section "parallel". Starting with version 0.5, steps in a stage must be in a steps block. @ line 12, column 9.
           stage('two') {
           ^

WorkflowScript: 4: Nothing to execute within stage "one" @ line 4, column 9.
           stage('one') {
           ^

WorkflowScript: 12: Nothing to execute within stage "two" @ line 12, column 9.
           stage('two') {
           ^

4 errors

Can someone please help me out why this is failing.

解决方案

You need to add a steps block after your stage declaration.

    pipeline {
    agent any
    stages {
        stage('Example Stage 1') {
            steps {
                parallel(
                        "step 1": { echo "hello" },
                        "step 2": { echo "world" },
                        "step 3": { echo "world" }
                )
            }
        }
        stage('Example Stage 2') {
            steps {
                parallel(
                        "step 1": { echo "hello" },
                        "step 2": { echo "world" },
                        "step 3": { echo "world" }
                )
            }
        }
    }
}

To Make your Stages Parallel use this, both solutions show up very similar in Blue Ocean :

    pipeline {
    agent any
    stages {
        stage('Example Stage') {
            parallel {
                stage('Stage 1') {
                    steps { sh 'echo stage 1 passed' }
                }
                stage('Stage 2') {
                    steps { sh 'echo stage 2 passed' }
                }
                stage('Stage 3') {
                    steps { sh 'echo stage 3 passed' }
                }
            }
        }
    }
}

这篇关于Jenkins 管道与并行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆