脚本管道语法中并行内的顺序阶段

时间:2020-02-14 16:54:56

标签: jenkins jenkins-pipeline jenkins-declarative-pipeline jenkins-blueocean

在我的Jenkinsfile中,我并行执行2个阶段,这些阶段之一将由其他几个连续阶段组成。当我运行脚本并检查BlueOcean中的管道时,该阶段顺序表示为一个单个节点。

(简化的)脚本如下:

node {
    stage('Stage 1') {...}
    stage('Stage 2') {...}
    stage('Stages 3 & 4 in parallel') {
        parallel(
            'Stage 3': {
                stage('Stage 3') {...}
            },
            'Stage 4': {
                stage('Stage 4a') {...}
                stage('Stage 4b') {...}
            }
        )
    }
}

所以在BlueOcean中,此脚本在阶段4中产生一个节点,而我希望看到两个节点,因为它由两个连续的阶段组成。

2 个答案:

答案 0 :(得分:5)

我也遇到了脚本管道的相同问题。如果您对声明性管道不满意,可以使用以下方法:

pipeline {
    agent any
    stages {
        stage('Stage 1') { steps {pwd()}}
        stage('Stage 2') { steps {pwd()}}
        stage('Stages 3 & 4 in parallel') {
            parallel {
                stage('Stage 3') { steps {pwd()}}
                stage('Stage 4') {
                    stages {
                        stage('Stage 4a') { steps {pwd()}}
                        stage('Stage 4b') { steps {pwd()}}
                    }
                }
            }
        }
    }
}

enter image description here

答案 1 :(得分:0)

使用最新版的jenkins 2.235.3和最新的插件,现在可以在脚本化管道中运行。

pipeline scripted image

node ('fetch') {
   stage('Stage 1') { sh(script:"echo Stage1",label: "sh echo stage 1")}
   stage('Stage 2') { sh(script:"echo Stage2",label: "sh echo stage 2")}
   stage('Stages 3 & 4 in parallel') {
       parallel(
           'Stage 3': {
            stage('Stage 3') {sh(script:"echo Stage3",label: "sh echo stage 3")}
           },
          'Stage 4': {
              stage('Stage 4a') {sh(script:"echo Stage4a",label: "sh echo stage 4a")}
              stage('Stage 4b') {sh(script:"echo Stage4b",label: "sh echo stage 4b")}
          }
      )
   }
}