我正在使用 Serenity BDD 作为我的自动化测试框架,现在我希望使用 HTML Publisher 插件将结果发布到 Jenkins。
当我的所有测试都通过时,没有问题,我可以毫无问题地发布报告,但如果 1 个测试失败,我会在发布阶段从 HTML Publisher 插件收到错误。我收到的错误是由于“TAR 存档被截断”造成的。不太确定这意味着什么。更深入地查看错误,我可以看到:
Caused by: java.io.IOException: Entry 'pagesource11965942031956863624.html' closed at '0' before the '106438' bytes specified in the header were written
,但我也不知道这意味着什么。
这是完整的错误(某些目录部分隐藏):
java.io.IOException: Failed to extract /home/jenkins/agent/workspace/*<someJenkinsDirs>*/target/site/serenity/**/*
at hudson.FilePath.readFromTar(FilePath.java:2982)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2742)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2706)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2694)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2677)
at htmlpublisher.HtmlPublisher.publishReports(HtmlPublisher.java:242)
at htmlpublisher.workflow.PublishHTMLStepExecution.run(PublishHTMLStepExecution.java:62)
at htmlpublisher.workflow.PublishHTMLStepExecution.run(PublishHTMLStepExecution.java:44)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Suppressed: java.util.concurrent.ExecutionException: java.io.IOException: Entry 'pagesource11965942031956863624.html' closed at '0' before the '106438' bytes specified in the header were written
at hudson.remoting.Channel$2.adapt(Channel.java:1036)
at hudson.remoting.Channel$2.adapt(Channel.java:1030)
at hudson.remoting.FutureAdapter.get(FutureAdapter.java:66)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2745)
... 12 more
Caused by: java.io.IOException: Entry 'pagesource11965942031956863624.html' closed at '0' before the '106438' bytes specified in the header were written
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.closeArchiveEntry(TarArchiveOutputStream.java:429)
at hudson.util.io.TarArchiver.visit(TarArchiver.java:117)
at hudson.util.DirScanner.scanSingle(DirScanner.java:51)
at hudson.util.DirScanner$Glob.scan(DirScanner.java:146)
at hudson.FilePath.writeToTar(FilePath.java:2943)
at hudson.FilePath$CopyRecursiveRemoteToLocal.invoke(FilePath.java:2908)
at hudson.FilePath$CopyRecursiveRemoteToLocal.invoke(FilePath.java:2893)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3492)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:376)
at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:121)
at java.base/java.lang.Thread.run(Unknown Source)
Suppressed: java.io.IOException: This archive contains unclosed entries.
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish(TarArchiveOutputStream.java:291)
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.close(TarArchiveOutputStream.java:309)
at hudson.util.io.TarArchiver.close(TarArchiver.java:124)
at hudson.FilePath.writeToTar(FilePath.java:2942)
... 12 more
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 61.0.33.251/61.0.33.251:52128
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
at hudson.remoting.Channel$2.adapt(Channel.java:1034)
at hudson.remoting.Channel$2.adapt(Channel.java:1030)
at hudson.remoting.FutureAdapter.get(FutureAdapter.java:66)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2745)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2706)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2694)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2677)
at htmlpublisher.HtmlPublisher.publishReports(HtmlPublisher.java:242)
at htmlpublisher.workflow.PublishHTMLStepExecution.run(PublishHTMLStepExecution.java:62)
at htmlpublisher.workflow.PublishHTMLStepExecution.run(PublishHTMLStepExecution.java:44)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.io.IOException: Truncated TAR archive
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.read(TarArchiveInputStream.java:743)
at java.base/java.io.InputStream.read(InputStream.java:205)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1309)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:978)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1282)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:953)
at hudson.util.IOUtils.copy(IOUtils.java:52)
at hudson.FilePath.readFromTar(FilePath.java:2972)
... 13 more
我也尝试过使用 archiveArtefacts,但我得到了完全相同的错误(猜测它们的工作方式相似)。
如何修复此错误?
编辑:
我对这个问题进行了更多的研究,发现 pagesource<random20numbers>.html
当测试失败或测试出错时生成(不确定是否在其他情况下生成此文件)。文件本身似乎是 Serenity 可以在测试失败/错误中“看到”的网页的 HTML 和 CSS 代码(即,测试失败时 Selenium Webdriver 正在查看的页面)。
我尝试使用简单的 rm pagesource<numbers>
删除 Jenkins 管道中的文件。命令,但遇到了权限问题(将与团队中的人员交谈以解决此问题),我还尝试使用 includes
HTML 发布者插件的参数。我尝试过的 Glob 表达式是 **/!(pagesource)*
但这会导致我收到错误:
ERROR: Directory '<someJenkinsDirs>/target/site/serenity' exists but failed copying to '<someJenkinsDirs>/builds/29/htmlreports/Serenity_20Report'.
最佳答案
我想更新这个问题的官方答案,因为我现在找到了一个可行的解决方案,它允许所有 Serenity Reporting 功能以及压缩/压缩报告并将其作为工件附加到构建或发布的能力Jenkins 管道中以另一种方式报告。 我决定将其添加为新答案,因为自从我发布上一个答案以来已经过去了大约 10 个月,这实际上更多的是一种解决方法/黑客,并没有真正解决问题,但仍然允许您使用以下命令压缩报告一些缺失的功能。请注意,这是从 the issue that I opened on the serenity-core Github 直接复制/粘贴的。 .
由于某种原因,pagesource<LotsOfNumbers>.html
文件与报告目录中生成的所有其他文件具有一些不同的权限,不知道为什么会出现这种情况。不管怎样,我只是简单地做了一个chmod -R 777 <mySerenityReportDirectory>
为所有用户授予对文件的完全权限。
此后我可以很容易地使用 tar
shell 命令在我的管道中执行,并对报告文件执行任何我想要的操作。就我而言,我使用 archiveArtifacts
插件以允许我下载报告的方式将报告添加到构建中。
人们应该牢记此解决方案的一些注意事项。我将 Jenkins 与 Kubernetes 结合使用,因此我有一个安装了 Maven 的容器,并且在该容器内运行测试执行命令 ( mvn clean verify [options]
) 和权限更改命令 ( chmod -R 777
)。运行chmod
尝试 tar
时,容器外部会导致操作不允许文件,我再次认为这与生成文件的权限有关。
这是我的一些管道代码:
container('maven') {
stage('Run tests') {
FAILED_STAGE = env.STAGE_NAME
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
currentBuild.displayName = params.BRANCH
currentBuild.description = params.TAG_FILTER;
sh("""
mvn -B clean integration-test \
-Denvironment=${params.ENVIRONMENT.toLowerCase()} \
-P ${params.TAG_FILTER.toLowerCase()} \
serenity:aggregate
""")
}
sh('chmod -R 777 target/site/serenity')
}
}
stage('Publish test report') {
FAILED_STAGE = env.STAGE_NAME
cucumber buildStatus: 'null', fileIncludePattern: '**/cucumber.json', jsonReportDirectory: 'target/cucumber-reports', reportTitle: 'Cucumber Test Report'
sh('tar -czf SerenityReport.tar.gz target/site/serenity')
archiveArtifacts(artifacts: "SerenityReport.tar.gz", fingerprint: true)
}
关于jenkins - HTML Publisher 插件无法提取(仅当 Serenity 测试失败时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73122995/