使用Jenkins html Publisher发布newman-reporter-htmlextra报告失败

时间:2019-05-20 08:07:21

标签: jenkins jenkins-pipeline newman

我在Jenkins pipeline中将newmannewman-reporter-htmlextra一起运行,生成了一个我想通过jenkins html publisher发布的html报告。

这是我正在使用的管道中的阶段

stage('Newman tests') {
steps() {
    script {
        dir("${JENKINS_HOME}/workspace/myproject") {
            sh 'newman run "./Collections/my_collection.postman_collection.json" --reporters cli,junit,htmlextra --reporter-junit-export "newman_result.xml" --reporter-htmlextra-export "newman_result.html"'
            junit "*.xml"
        }
    }
    publishHTML target: [
            allowMissing: false,
            alwaysLinkToLastBuild: false,
            keepAll: true,
            reportDir: '.',
            reportFiles: 'newman_result.html',
            reportName: 'Newman HTML Reporter'
    ]
}

它正在运行,并在我的Newman HTML Reporter项目中创建条目Jenkins

但是,当我打开此类报告时,该报告为空,请检查screenshot

有什么想法吗?

非常感谢, 基督徒

1 个答案:

答案 0 :(得分:1)

我想您要发布html结果时访问的文件夹错误。 您正在不在常规的jenkins工作区中创建文件:

dir("${JENKINS_HOME}/workspace/myproject") {
    sh 'newman run "./Collections/my_collection.postman_collection.json" --reporters cli,junit,htmlextra --reporter-junit-export "newman_result.xml" --reporter-htmlextra-export "newman_result.html"'
    junit "*.xml"
}

离开script{}后,您将访问Jenkins的原始工作区,因此reportDir: '.'与文件所在的文件夹不同,这意味着没有文件=无法显示html。

您在这里有3个选择:

  1. 您可以在Jenkins的常规工作区中创建文件

  2. HTML Publisher插件的目标是正确的文件夹

  3. 将HTML Publisher插件放入dir{}的范围内,就像处理junit plugin

  4. 一样

要轻松找出要访问哪个文件夹的范围,可以运行echo pwd。一次在您的dir{}范围内执行一次,一次在您的插件范围内执行一次,那么应该清楚您插件的reportDir是错误的。