Jenkinsfile 管道 DSL:如何在作业仪表板 GUI 中显示多列 - 适用于所有动态创建的阶段 - 在 PIPELINE 部分中时 [英] Jenkinsfile Pipeline DSL: How to Show Multi-Columns in Jobs dashboard GUI - For all Dynamically created stages - When within PIPELINE section

查看:21
本文介绍了Jenkinsfile 管道 DSL:如何在作业仪表板 GUI 中显示多列 - 适用于所有动态创建的阶段 - 在 PIPELINE 部分中时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins 2.89.4 滚动

我看到了几乎所有的 stackoverflow 帖子,这些帖子展示了我们如何成功运行并行步骤/阶段(使用列表/映射等)——或者直接对它们进行硬编码——或者甚至为 Jenkinsfile 创建动态阶段(如本文所示:脚本化 jenkinsfile 并行阶段)

我的要求是:

  1. 在构建"步骤下构建 N 个项目的管道,即在每个项目上并行构建.即它在所有 N 个项目上运行 Gradle.在这里,我有一个由声明性 JOB DSL Groovy 创建的 Jenkinsfile.这里我的 Gradle 项目没有设置为多项目,所以我不能调用顶级 gradle 说,Gradle 请在 Gradle 中发挥你的平行魔法.

  2. 我想在这些 N 个项目的自己独立的并行动态创建阶段(GUI 列)中运行构建,如 jenkins 工作的仪表板所示.p>

  3. 我想分别查看(Gradle 构建/控制台)每个项目构建的输出,即 我不想混合并行运行的每个项目构建的控制台输出只有一列(即名为BUILD的列).

  4. 在这个 URL https://jenkins.io/blog/2017/09/25/declarative-1/ 我明白了,你可以如何运行并行阶段/步骤,但这样做,要么将这些并行步骤的输出混合在一列中(我的意思是在 BUILD 列)--或者,如果您希望它在不同的阶段/列下(即帖子说在 Linux 或 Windows 上测试 单独那么您仍然在早期对 Jenkinsfile 中的所有阶段/步骤进行硬编码(而不是仅使用列表或数组哈希,我更愿意更新以添加更多或更少的阶段/并行步骤,就像我的情况一样,它们都遵循相同的标准.我想要的是只在一个地方更新多少个步骤以及一个地方的所有阶段是什么(列表/数组).

  5. 使用Jenkins蓝海现在.

通常,如果您在一个阶段中有并行步骤,则当您单击以查看给定并行步骤/阶段的控制台输出时,所有步骤的控制台标准输出会混合到一个控制台输出/阶段/列中;当您将鼠标悬停在作业仪表板中的 BUILD 列上时(假设在 BUILD 阶段有并行步骤)(所有这些步骤的标准输出混杂在一起,很难看到单个项目步骤的控制台输出仅用于给定的步骤/阶段).

如果我们想(动态地)创建单独的阶段,那么 Jenkins 应该能够在并行部分中显示给定步骤/动态阶段的控制台输出(即每列应该显示他们自己项目的构建控制台输出).

使用上面的 URL,我可以在尝试这个脚本后执行以下操作:

//主脚本块//可以使用例如.params.parallel 构建参数以选择并行/串行def runParallel = true定义构建阶段节点('主'){阶段('初始化并行动态阶段'){//设置List>描述构建buildStages = prepareBuildStages()println("初始化管道.")}for(在 buildStages 中构建){如果(运行并行){并行(构建)} 别的 {//串行运行(注意.地图是无序的!)for (build in builds.values()) {构建调用()}}}阶段('完成'){println('整个SHENZI就完成了.')}}//创建适合的构建阶段列表def prepareBuildStages() {def buildList = []对于 (i=1; i<4; i++) {def buildStages = [:]for ( ['Alpha', 'Tango', 'Cyarli' 中的名称] ) {def n = "${name} ${i}"buildStages.put(n, prepareOneBuildStage(n))}buildList.add(buildStages)}返回构建列表}def prepareOneBuildStage(字符串名称){def proj_name = name.split(' ')[0]def proj_parallel_sub_step = name.split(' ')[1]//返回整个chunkoni返回 {stage("Build
Project-${proj_name}
Step ${proj_parallel_sub_step}") {println("建筑物 ${proj_name} - ${proj_parallel_sub_step}")sh(脚本:'睡眠 15',返回状态:真)}}}

当我将上述 Groovy 脚本(正在创建 DYNAMIC Stages)放入 Pipeline ScriptPipeline Script from SCM(即 .groovy 文件)——它成功运行并在 BUILD 步骤下为 3 个项目中的每一个创建动态阶段,并为所有 3 个项目并行运行 3 个步骤(第 N 个),然后为所有 3 个项目启动下一个第 N 个步骤,依此类推.

如果您在下面看到,我们还在 Jenkins 工作仪表板中为他们提供了单独的列.

现在,当我将上面的脚本放在 Jenkinsfile(Pipeline DSL)我有的地方 pipeline { .... } 部分时,它不起作用并且给了我以下错误.

使用我的 JOB DSL,我创建了一个新的 Jenkins 流水线作业,其中 来自 SCM 的流水线脚本 调用一个 groovy 文件(现在包含):

//-----------------------------------------------------//两者 - JF Jenkins 作业中的并行运行和 GUI 视图.//----------------------------------------------------def runParallel = true定义构建阶段def wkspace =/var/lib/jenkins/workspaces/ignore_this_variale_or_its_value_for_now//创建适合的构建阶段列表def prepareBuildStages() {def buildList = []对于 (i=1; i<3; i++) {def buildStages = [:]for ( ['Alpha', 'Tango', 'Cyarli' 中的名称] ) {def n = "${name} ${i}"buildStages.put(n, prepareOneBuildStage(n))}buildList.add(buildStages)}返回构建列表}//---def prepareOneBuildStage(字符串名称){def proj_name = name.split(' ')[0]def proj_parallel_sub_step = name.split(' ')[1]//返回整个 chunkoni (i.e. 对于给定的阶段) - 将被动态命名.返回 {stage("Build
Project-${proj_name}
Step ${proj_parallel_sub_step}") {println("建筑物 ${proj_name} - ${proj_parallel_sub_step}")sh(脚本:'睡眠 15',返回状态:真)}}}//设置List>描述构建buildStages = prepareBuildStages()//------字符串 jenkinsBaselines//立即查看 --- 我们将这一部分称为管道"管道{代理人 {节点{标签rhat6"自定义工作区 wkspace}}选项 {ansiColor('xterm')超时(时间:8,单位:'小时')跳过默认结账()时间戳()}环境 {someEnvVar = 'aValue'}//------------ 阶段阶段{阶段('初始化并行动态阶段'){//设置List>描述构建println("初始化管道.")}for(在 buildStages 中构建){如果(运行并行){并行(构建)} 别的 {//串行运行(注意.地图是无序的!)for (build in builds.values()) {构建调用()}}}阶段('完成'){println('整个SHENZI就完成了.')}}//------}

现在运行 Jenkinsfile Jenkins 作业给我这个错误:

[BFA] 正在扫描构建以查找已知原因...[BFA] 未发现故障原因[BFA] 完成.1sorg.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:WorkflowScript:69:不是有效的阶段部分定义:buildStages = prepareBuildStages()".需要一些额外的配置.@ 第 69 行,第 5 列.阶段('初始化并行动态阶段'){^WorkflowScript:69:未知阶段部分println".从 0.5 版本开始,阶段中的步骤必须在步骤块中.@ 第 69 行,第 5 列.阶段('初始化并行动态阶段'){^WorkflowScript: 75: 预期阶段@第 75 行,第 5 列.for(在 buildStages 中构建){^WorkflowScript:86:未知阶段部分println".从 0.5 版本开始,阶段中的步骤必须在步骤块中.@ 第 86 行,第 5 列.阶段('完成'){^WorkflowScript:69:在阶段初始化并行动态阶段"@第 69 行,第 5 列中没有要执行的步骤"或并行".阶段('初始化并行动态阶段'){^WorkflowScript:86:在阶段完成"@第 86 行,第 5 列中没有要执行的步骤"或并行".阶段('完成'){^6 错误在 org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)在 org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)在 org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)在 org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)在 org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)在 groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)在 groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)在 groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)在 groovy.lang.GroovyShell.parse(GroovyShell.java:700)在 org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)在 org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)在 org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)在 org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)在 org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)在 hudson.model.ResourceController.execute(ResourceController.java:97)在 hudson.model.Executor.run(Executor.java:429)完成:失败

我怎样才能在 Jenkinsfile pipeline 部分工作,并且仍然能够为给定的项目 N 和步骤 M 获取每个动态创建的阶段的单独列?

试了下面的方法,还是报错.

//------------- 阶段阶段{阶段('初始化并行动态阶段'){//设置List>描述构建buildStages = prepareBuildStages()println("初始化管道.")//也尝试过这种方式.一个阶段内buildStages.each { bld -->平行(BLD)}}阶段('完成'){println('整个SHENZI就完成了.')}}//------

解决方案

所以我对此进行了一些研究并使其正常工作.

Jenkinsfile 中的新代码(用于 STAGES)现在是:

//------------- 阶段阶段{阶段('启动管道'){脚步 {脚本 {sh "echo HELLO moto razr!"}}}stage('初始化并行动态阶段'){脚步 {脚本 {//并行运行所有项目的所有第 N 步.buildStages.each { bs ->并行(bs)}//或取消注释以下代码(如果以布尔变量为条件)./*for(在 buildStages 中构建){如果(运行并行){并行(构建)} 别的 {//串行运行(注意.地图是无序的!)for (build in builds.values()) {构建调用()}}}*/}}}阶段('完成'){println('整个SHENZI就完成了.')}}//------

这就是工作所需的全部.

为了清晰的消息/阶段名称,我也调整了函数,我们不会在 pipeline { ... }

中设置这个变量 buildStages

//---def prepareOneBuildStage(字符串名称){def proj_name = name.split(' ')[0]def proj_parallel_sub_step = name.split(' ')[1]//返回整个 chunkoni (i.e. 对于给定的阶段) - 将被动态命名.返回 {阶段(构建项目-${proj_name} Parallel_Step_${proj_parallel_sub_step}"){println("Parallel_Step # ${proj_parallel_sub_step} of Project => ${proj_name}")sh(script:"echo "Parallel_Step # ${proj_parallel_sub_step} of Project => ${proj_name}" && sleep 20", returnStatus:true)//-- 或者 -- 您可以在此处调用 Gradle 任务,即 rpm/任何其他/任何其他命令.}}}//设置List>描述构建.现在部分.buildStages = prepareBuildStages()//------

这个实现现在创建N没有.并行阶段,即每个项目的单独列,用于给定的第 N 个步骤(查看 Jenkinsfile 作业的仪表板时)对于 P 号的项目.

  1. 它将并行运行所有 P 项目,用于给定的N步.
  2. 它将等待所有项目的第 N 步先完成,然后跳到下一个第 N 步.

    这意味着,如果 Project ALPHA Step #1 完成,它仍然会等待其他 2 个项目的所有 Step #1,然后并行启动所有项目的 Step #2.

  3. 挑战:我们如何才能在 ALPHA 项目的第 1 步完成后立即开始 ALPHA 项目的第 2 步,即它不会等待其他 2 个项目的第 1 步完成并可能与其他项目的步骤 N(=1) 或 N+1 并行运行 ALPHA 项目 1 的步骤 #2.

    这假设所有项目都是相互独立的,并且项目不会在任何其他项目/阶段/步骤中共享由给定项目/他们的阶段/步骤生成的内容.

根据您自己的要求,您可能需要等待(即在所有项目的第 1 步完全完成之前不要运行所有项目的第 2 步)--OR-- 您可能想要运行 ALPHA 的第 2 步 项目,比方说 - 探戈的第 2 步 项目同时项目 CHYARLI's第 1 步仍在进行中.

由于这篇文章的主要范围是为每个项目获取单独的动态创建的列/阶段(在 pipeline { ... } 部分中并行运行),我想,我得到了我想要的寻找.

注意:如果您想运行管道的并发构建,可以轻松使用并行.有关运行parallel构建操作并发相关问题的更多信息,请参见此处:Jenkins - java.lang.IllegalArgumentException:最后一个单元没有足够的有效位 &Gradle 错误:在根项目中找不到任务null"

Jenkins 2.89.4 rolling

I saw almost all stackoverflow posts which show how we can successfully run parallel steps/stages (using list/maps etc) --OR hardcoding them directly --OR even create dynamic stages for Jenkinsfile (as seen in this post: Scripted jenkinsfile parallel stage)

My requirements are:

  1. A pipeline which builds N. no of projects under "BUILD" steps i.e. parallel builds on each of those projects. i.e. it runs Gradle on all N projects. Here I have a Jenkinsfile which was created by a declarative JOB DSL Groovy. Here my Gradle projects are not set as multi-projects so I can't call the top level gradle and say, Gradle please do your parallel magic (within Gradle).

  2. I want to run build of these N projects in their own separate parallel dynamically created stages (GUI Columns) as seen in jenkins job's dashboard.

  3. I want to see the output of (Gradle build/console) each project's build separately i.e. I don't want to mix the console output of each projects build which are running in parallel in just ONE COLUMN (i.e. column named BUILD).

  4. In this URL https://jenkins.io/blog/2017/09/25/declarative-1/ I see, how you can run parallel stages/steps but in doing so, either it's mixing those parallel step's output in just one column (I mean under BUILD column) --OR if you want it under separate stages/columns (i.e. the post says Test on Linux or Windows separately then you are still hard-coding all the stages/steps in Jenkinsfile early on (rather than using just a list or array hash which I'd prefer to update for adding more or less stages / parallel steps as in my case, they all follow the same standard). What I want is to just update in one place How many steps and what are all of the stages in just one place (list/array).

  5. I'm not using Jenkins Blue Ocean for now.

Usually if you have parallel steps within a stage, their console std output for all steps gets mixed into one console output / stage/column when you click to see the console output for that given parallel step/stage; When you hover over the BUILD column (assuming there were parallel steps in BUILD stage) in job's dashboard (std output for all those steps is mixed up and very hard to see individual project step's console output just for a given step/stage).

If we want to create separate stages (dynamically) then Jenkins should be able to show console output of a given step/dynamic stage within the parallel section (i.e. each column should show their own project's build console output).

Using the above URL, I'm able to do the following after trying this script:

// main script block
// could use eg. params.parallel build parameter to choose parallel/serial 
def runParallel = true
def buildStages

node('master') {
  stage('Initializing Parallel Dynamic Stages') {
    // Set up List<Map<String,Closure>> describing the builds
    buildStages = prepareBuildStages()
    println("Initialised pipeline.")
  }

  for (builds in buildStages) {
    if (runParallel) {
      parallel(builds)
    } else {
      // run serially (nb. Map is unordered! )
      for (build in builds.values()) {
        build.call()
      }
    }
  }

  stage('Done') {
      println('The whole SHENZI is complete.')
  }
}

// Create List of build stages to suit
def prepareBuildStages() {
  def buildList = []

  for (i=1; i<4; i++) {
    def buildStages = [:]
    for (name in [ 'Alpha', 'Tango', 'Chyarli' ] ) {
      def n = "${name} ${i}"
      buildStages.put(n, prepareOneBuildStage(n))
    }
    buildList.add(buildStages)
  }
  return buildList
}

def prepareOneBuildStage(String name) {
    def proj_name = name.split(' ')[0]    
    def proj_parallel_sub_step = name.split(' ')[1]

    //Return the whole chunkoni
    return {
            stage("Build
Project-${proj_name}
Step ${proj_parallel_sub_step}") {
                println("Building ${proj_name} - ${proj_parallel_sub_step}")
                sh(script:'sleep 15', returnStatus:true)
            }
    }
}

When I'm putting the above Groovy Script (which is creating DYNAMIC Stages) inside Pipeline Script or Pipeline Script from SCM (i.e. the same code available in a .groovy file) -- it runs successfully and creates dynamic stages under BUILD step for each of the 3 projects and runs 3 steps (Nth) for all 3 projects in parallel and then starts the next Nth step for all 3 projects and so on.

If you see below, we also got individual columns in Jenkins job dashboard for them.

Now, When I put the above script in Jenkinsfile (Pipeline DSL) where I have pipeline { .... } section, it's not working and giving me the following error.

Using my JOB DSL, I created a new Jenkins Pipeline job where Pipeline Script from SCM calls a groovy file (which now contains):

//----------------------------------------------------
// Both - Parallel Run and GUI View in JF Jenkins job.
//----------------------------------------------------
def runParallel = true
def buildStages
def wkspace = /var/lib/jenkins/workspaces/ignore_this_variale_or_its_value_for_now

// Create List of build stages to suit
def prepareBuildStages() {
  def buildList = []

  for (i=1; i<3; i++) {
    def buildStages = [:]
    for (name in [ 'Alpha', 'Tango', 'Chyarli' ] ) {
      def n = "${name} ${i}"
      buildStages.put(n, prepareOneBuildStage(n))
    }
    buildList.add(buildStages)
  }
  return buildList
}
//---
def prepareOneBuildStage(String name) {
  def proj_name = name.split(' ')[0]
  def proj_parallel_sub_step = name.split(' ')[1]
  // return the whole chunkoni (i.e. for a given stage) - will be named dynamically.
  return {
    stage("Build
Project-${proj_name}
Step ${proj_parallel_sub_step}") {
      println("Building ${proj_name} - ${proj_parallel_sub_step}")
      sh(script:'sleep 15', returnStatus:true)
    }
  }
}
// Set up List<Map<String,Closure>> describing the builds
buildStages = prepareBuildStages()
//---------------------




String jenkinsBaselines

// SEE NOW --- we have this section called 'pipeline'
pipeline {
    agent {
        node {
            label 'rhat6'
            customWorkspace wkspace
        }
    }

    options {
        ansiColor('xterm')
        timeout(time: 8, unit: 'HOURS')
        skipDefaultCheckout()
        timestamps()
    }

    environment {
        someEnvVar = 'aValue'

    }

    //------------- Stages
    stages {
        stage('Initializing Parallel Dynamic Stages') {
            // Set up List<Map<String,Closure>> describing the builds
            println("Initialised pipeline.")
        }

        for (builds in buildStages) {
            if (runParallel) {
                parallel(builds)
            } else {
                // run serially (nb. Map is unordered! )
                for (build in builds.values()) {
                    build.call()
                }
            }
        }

        stage('Done') {
            println('The whole SHENZI is complete.')
        }      
    }
    //---------------------
}

Running the Jenkinsfile Jenkins job now gives me this error:

[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 1s
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 69: Not a valid stage section definition: "buildStages = prepareBuildStages()". Some extra configuration is required. @ line 69, column 5.
            stage('Initializing Parallel Dynamic Stages') {
       ^

WorkflowScript: 69: Unknown stage section "println". Starting with version 0.5, steps in a stage must be in a steps block. @ line 69, column 5.
            stage('Initializing Parallel Dynamic Stages') {
       ^

WorkflowScript: 75: Expected a stage @ line 75, column 5.
            for (builds in buildStages) {
       ^

WorkflowScript: 86: Unknown stage section "println". Starting with version 0.5, steps in a stage must be in a steps block. @ line 86, column 5.
            stage('Done') {
       ^

WorkflowScript: 69: No "steps" or "parallel" to execute within stage "Initializing Parallel Dynamic Stages" @ line 69, column 5.
            stage('Initializing Parallel Dynamic Stages') {
       ^

WorkflowScript: 86: No "steps" or "parallel" to execute within stage "Done" @ line 86, column 5.
            stage('Done') {
       ^

6 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:133)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

How can I get this working in Jenkinsfile pipeline section and still able to get individual columns per dynamically created stage for a given project N and Step M?

Tried the following way, still errors the say way.

//------------- Stages
stages {
    stage('Initializing Parallel Dynamic Stages') {
        // Set up List<Map<String,Closure>> describing the builds
        buildStages = prepareBuildStages()
        println("Initialised pipeline.")

        // tried this way too. within a stage
        buildStages.each { bld -->
            parallel(bld)
        }  
    }

    stage('Done') {
        println('The whole SHENZI is complete.')
    }      
}
//---------------------

解决方案

So I did some poking into this and got it working.

The new code within Jenkinsfile (for STAGES) is now:

//------------- Stages
stages {
     stage('Start Pipeline') {
        steps {
            script {
                sh "echo HELLO moto razr!"
            }
        }  
     }

    stage('Initializing Parallel Dynamic Stages'){
        steps {
            script {
                // Run all Nth step for all Projects in Parallel. 
                buildStages.each { bs -> parallel(bs) }


                // OR uncomment the following code (if conditional on boolean variable).
                /*
                for (builds in buildStages) {
                    if (runParallel) {
                        parallel(builds)
                    } else {
                        // run serially (nb. Map is unordered! )
                        for (build in builds.values()) {
                            build.call()
                        }
                    }
                }
                */        

            }   
        }
     } 

    stage('Done') {
        println('The whole SHENZI is complete.')
    }      
}
//---------------------

That's all it took to work.

For clear messages / stage names, I tweaked the function as well and We won't set this variable buildStages within pipeline { ... }

//---
def prepareOneBuildStage(String name) {
  def proj_name = name.split(' ')[0]
  def proj_parallel_sub_step = name.split(' ')[1]
  // return the whole chunkoni (i.e. for a given stage) - will be named dynamically.
  return {
    stage("BUILD Project-${proj_name} Parallel_Step_${proj_parallel_sub_step}") {
      println("Parallel_Step # ${proj_parallel_sub_step} of Project => ${proj_name}")
      sh(script:"echo "Parallel_Step # ${proj_parallel_sub_step} of Project => ${proj_name}" && sleep 20", returnStatus:true)
      // -- OR -- you can call Gradle task i.e. rpm / any other / any other command here. 
    }
  }
}

// Set up List<Map<String,Closure>> describing the builds. section now.
buildStages = prepareBuildStages()
//---------------------

This implementation is now creating N no. of parallel stages i.e. a separate column per project for a given Nth step (when looking at Jenkinsfile job's dashboard) for P no. of projects.

  1. It will run All P projects for a given Nth step in parallel.
  2. It will wait for Nth step for all Projects to complete first and then jump to the next Nth step.

    What this means is, if Project ALPHA Step #1 is complete, it'll still wait for all Step #1 of other 2 projects and then launch Step #2 of all projects in parallel.

  3. Challenge: How can we make ALPHA Project's Step #2 to start as soon as ALPHA project's Step #1 is complete i.e. it won't wait for Step 1 of other 2 projects to complete and could possibly run Step #2 of ALPHA project 1 in parallel with Step N(=1) or N+1 of other projects.

    This assumes all projects are independent of each other and projects don't share contents generated by a given project/their stage/steps in any other project/stage/step.

Depending upon your own requirements, you may want to wait (i.e. don't run Step 2 of all projects until Step 1 of all projects are fully complete) --OR-- you may want to run Step 2 of ALPHA project with let's say - Step 2 of TANGO project while project CHYARLI's step 1 is still in progress.

As the main scope of this post was to get separate dynamically created columns/stages per project (running in parallel within pipeline { ... } section), I think, I got what I was looking for.

NOTE: Go easy with parallel if you want to run concurrent builds of a pipeline. For more info about issues related to running parallel build actions concurrently, see here: Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits & Gradle error: Task 'null' not found in root project

这篇关于Jenkinsfile 管道 DSL:如何在作业仪表板 GUI 中显示多列 - 适用于所有动态创建的阶段 - 在 PIPELINE 部分中时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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