在报告中显示Jenkins并行任务,如阶段

时间:2018-03-15 17:18:11

标签: jenkins jenkins-pipeline

所以我设法在运行两个作业的Jenkins管道中获得并行构建执行:“单元测试”和“E2E测试”,但我能使其工作的唯一方法是在单个“测试”阶段内,如下所示:

pipeline {
    agent any
    stages {
        stage('Testing') {
            steps {
                parallel("Unit Tests": {
                    echo "Running Tests"
                    build 'Jenkins Job 1'
                },
                "E2E Tests": {
                    build 'Jenkins Job2'
                }
                )
            }
        }
        stage('Deploy') {
            steps {
                parallel("first": {
                    echo "Open a ticket to deploy"
                },
                        "second": {
                            echo "Confirm when ticket was approved"
                        }
                )
            }
        }
    }
}

目前,这会产生如下构建报告: enter image description here

我们的目标是获得一份如下所示的报告: enter image description here

那么,我们如何在单独的阶段视图中获取两个构建作业,同时保持它们并行运行?我无法做到这一点......

1 个答案:

答案 0 :(得分:0)

尝试将其更改为:

pipeline {
    agent any
    stages {
        stage('Tests') {
            steps {
                script {
                    def tests = [:]

                    stage("Unit Tests") {
                        tests["Unit Tests"] = {
                            build 'Jenkins Job 1'
                        }
                    }
                    stage("E2E Tests") {
                        tests["E2E Tests"] = {
                            build 'Jenkins Job 2'
                        }
                    }
                    parallel tests
                }
            }
        }
    }
}