如何在 Jenkins 并行管道中使用 allure?

How to use allure with Jenkins parallel pipelines?

如何将 Allure 与 Jenkins 并行管道一起使用?

我有一个 Jenkins 管道到 运行 并行测试:

def testName="ExampleTest"
pipeline {
    agent any
    stages {
        stage ('Checkout test') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/devel']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab', url: 'git@git.***']]])
            }
        }
        stage ('Test Template') {
            parallel {
                stage ('testTemplate1') {
                    steps {
                        runTestByName (testName,STAGE_NAME)
                    }
                }
                stage ('testTemplate2') {
                    steps {
                        runTestByName (testName,STAGE_NAME)
                    }
                }
            }
        }
    }
}

void runTestByName (testName,testTemplate) {
    stage (testName + ':' + testTemplate) {
        withEnv(["JAVA_HOME=${env.JAVA_HOME}", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]) {
            withCredentials([usernamePassword(credentialsId: 'credentials', passwordVariable: 'PASSWORD', usernameVariable: 'LOGIN')]) {
                withMaven(jdk: '', maven: 'maven-default', mavenSettingsFilePath: '/var/jenkins_home/secrets/settings.xml') {
            sh "mvn -X -Dtest="+testName+" -Dtemplate="+testTemplate+" test "
                }
            }
        }
    }
    stage ('Reporting:' + testName + ':' + testTemplate) {
        allure includeProperties: false, jdk: '', results: [[path: 'target/allure-results']]
    }
}

测试以正确的方式执行,生成了报告,但所有报告都是相同的(换句话说,我得到了 2 份带有参数 'testTemplate2' 的测试报告,我期望带有 [=34] 的测试报告=] 并使用 'testTemplate2').

报告测试

更新:

我添加了 属性 allure.results.directory 到 maven:

sh "mvn -X -Dtest="+testName+" -Dtemplate="+testTemplate+" -Dallure.results.directory=target/allure-results/${testTemplate} test "

我也更改了 allure 配置:

allure ([
                includeProperties: false,
                jdk: '',
                results: [[path: "target/allure-results/${testTemplate}"]],
                report: "allure-report/${testTemplate}"
            ])

我看到两个报告都已成功生成(来自控制台日志):

[test-parallel@2] $ /var/jenkins_home/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure-default/bin/allure generate /var/jenkins_home/workspace/test-parallel@2/target/allure-results/testTemplate1 -c -o /var/jenkins_home/workspace/test-parallel@2/allure-report/testTemplate1
Report successfully generated to /var/jenkins_home/workspace/test-parallel@2/allure-report/testTemplate1
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.

[test-parallel@2] $ /var/jenkins_home/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure-default/bin/allure generate /var/jenkins_home/workspace/test-parallel@2/target/allure-results/testTemplate2 -c -o /var/jenkins_home/workspace/test-parallel@2/allure-report/testTemplate2
Report successfully generated to /var/jenkins_home/workspace/test-parallel@2/allure-report/testTemplate2
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.

但是当我尝试从 Jenkins 打开报告时出现 404 错误。

有什么办法可以解决这个问题吗?

@yarafed 所以这是我的解决方法,正如我之前在评论中提到的,我已经创建了并行生成其他作业的 DSL 作业。 我不得不删除个人数据和其他一些实施功能,但这里是:

def testName='Test'
def tags = ['tag1', 'tag2', 'tag3']
def threads = 4
def parallelStagesMap = tags.collectEntries {
    ["${it}" : generateStage(it,testName,threads)]
}
def generateStage(tag, testName,threads) {
    return {
        stage("stage: ${tag}") {
            runTestByName (testName,tag,threads)
        }
    }
}
void runTestByName (testName, tag, threads) {
    def jobName=testName.concat('-').concat(tag).replace(':','-')
    jobDsl scriptText: '''
    freeStyleJob("''' + jobName + '''"){
        scm {
            git {
                branch('devel')
                remote {
                    name('remote')
                    url('<git link here>')
                    credentials ('<credentials id here>')
                }
            }
        }
        wrappers {
            credentialsBinding {
                usernamePassword('LOGIN','PASSWORD','credentials')
            }
        }
        steps {
            maven {
                goals ('clean')
                goals ('test')
                mavenInstallation('maven-default')
                injectBuildVariables(true)
                property('test',"''' + testName + '''")
                property('parallel','methods')
                property('threadcount',"''' + threads + '''")
                property('tag',"''' + tag + '''")
                property('user','$USER')
                property('password','$PASSWORD')
            }
        }
        publishers { 
            allure (['target/allure-results']) {}
        }
    }
    '''
    build job:jobName
}
pipeline {
    agent any
    stages {
        stage ('Test') {
            steps {
                script {
                    parallel parallelStagesMap
                }
            }
        }
    }
}