Allure 结果已生成(xml),可以通过在 allure-results 目录外运行 allureserve 来查看,但是当使用具有 Jenkins 工作区相对路径的 allure 结果目录在 Jenkins 中配置时,找不到 allure 结果。估计路径有问题
[allure_test] $ /Users/me/.jenkins/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/Allure_2.7.0/bin/allure 生成-c -o /Users/me/.jenkins/workspace /allure_test/allure-report 诱惑结果不存在 报告已成功生成到 /Users/me/.jenkins/workspace/allure_test/allure-report Allure 报告已成功生成。
为魅力报告定义的相对路径是
../../repos/partner-portal/target/allure-results
报告已生成,但没有结果
我就因为这个问题奋斗了24小时以上,整夜无法入睡。没有与此相关的明确说明及其工作原理。终于我明白了。
这个答案可能有点太晚了,但是您能否在工作区中创建“allure-results”文件夹(如 /Users/me/.jenkins/workspace/allure_test/allure-results)?
在 jenkins 中配置 Allure 报告并使用Behavior 命令后,我终于看到以下输出并在我的 jenkins 构建计划中看到工作报告:
.
.
.
.
D:\PythonProject\PythonBehave>behave -f allure_behave.formatter:AllureFormatter -o C:\Users\Alex\.jenkins\workspace\PythonAllure\allure-results D:\PythonProject\PythonBehave\features
Failing scenarios:
features/example.feature:17 user can search text in google -- @2.2 Incorrect
features/github_login.feature:13 User attempt to login with wrong username and password -- @1.1 InCorrect
features/github_login.feature:14 User attempt to login with wrong username and password -- @1.2 InCorrect
features/github_login.feature:18 User attempt to login with correct username and password
0 features passed, 2 failed, 0 skipped
3 scenarios passed, 4 failed, 0 skipped
12 steps passed, 4 failed, 8 skipped, 0 undefined
Took 3m24.651s
D:\PythonProject\PythonBehave>exit 1
Build step 'Custom Python Builder' marked build as failure
[PythonAllure] $ C:\Users\Alex\.jenkins\tools\ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation\Allure_2.13.1\bin\allure.bat generate C:\Users\Alex\.jenkins\workspace\PythonAllure\allure-results -c -o C:\Users\Alex\.jenkins\workspace\PythonAllure\allure-report
Report successfully generated to C:\Users\Alex\.jenkins\workspace\PythonAllure\allure-report
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
Finished: FAILURE
之前,当我的工作区中没有 allure-results 文件夹时,我会得到此输出:
[PythonAllure] $ C:\Users\Alex\.jenkins\tools\ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation\Allure_2.13.1\bin\allure.bat generate -c -o C:\Users\Alex\.jenkins\workspace\PythonAllure\allure-report
我们没有在 UI 上使用任何构建后步骤,而是使用 jenkins pipeline groovy 脚本,如下所示:
def allureReportsGenerationTask() {
try {
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'target/allure-results']]])
} catch(Exception error) {
println("Caught Exception: ${error}")
}
}
项目结构就是这样
ProjectRepo
- src
- target
-alure-results
- pom.xml
- testng.xml
在这种情况下,我们得到了生成的 allure 结果,但它没有在 Jenkins 管道 allure 插件中被选中。 ON UI 下面的命令始终运行
/opt/jenkins/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure/bin/allure generate -c -o /opt/jenkins/workspace/ProjectRepoPipeline/allure-report
您可以看到 Jenkins 无法在上面的 Jenkins 管道命令中找到用于生成参数的 allure-results
我们在 pom.xml maven-surefire-plugin 中添加了以下参数
<systemPropertyVariables>
<allure.results.directory>../target/allure-results</allure.results.directory>
</systemPropertyVariables>
现在项目结构变成了
-ProjectRepo - 源代码 - pom.xml - testng.xml
现在通过管道脚本运行相同的内容,我们可以运行以下命令
/opt/jenkins/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure/bin/allure generate /opt/jenkins/workspace/ProjectRepoPipeline/target/allure-results -c -o /opt/jenkins/workspace/ProjectRepoPipeline/allure-report
ProjectRepoPipeline - 这是运行 CI/CD 的 Jenkins 管道名称