Azure DevOps手动执行Serenity流水线遇文件缺失错误求助
执行Serenity流水线时出现以下错误:
Error: ENOENT: no such file or directory, stat 'E:\V\01-Au04\_work\36\s\target\site\serenity' Archive files ENOENT: no such file or directory, stat 'E:\V\01-Au04\_work\36\s\target\site\serenity' Archive files Publishing build artifacts failed with an error: Not found PathtoPublish: E:\V\01-Au04\_work\36\s\target\site\serenity\serenity-summary.html Publish Single page report Unable to process command '##vso[task.addattachment type=replacedhtml;name=content;]E:\V\01-Au04\_work\36/s/target/site/serenity/serenity-summary.html' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296) Publish HTML report Value cannot be null. (Parameter 'Cannot upload task attachment file, attachment file location is not specified or attachment file not exist on disk') Publish HTML report
同时收到警告:
Directory 'E:\V\01-Au04\_work\36\a' is empty. Nothing will be added to build artifact 'Full report'. Publish Full report
排查解决步骤
确认Serenity报告生成任务是否成功完成
检查流水线日志中测试执行阶段的输出,确认Maven/Gradle的测试命令(如mvn verify、gradle test aggregate)是否正常执行完毕,没有编译错误、测试失败中断的情况。如果任务未完成,target/site/serenity目录不会生成。同时可以在本地执行相同命令,验证本地能否正常生成报告目录及文件。核对流水线工作目录与报告路径
错误中指向的路径是E:\V\01-Au04\_work\36\s\target\site\serenity,确认Serenity任务的执行目录是$(Build.SourcesDirectory)(即流水线的s目录)。如果任务在其他路径执行,报告生成位置会偏离预期。修正归档/发布任务的路径配置
检查YML中Archive Files、Publish Build Artifacts、Publish HTML Report等任务的路径参数:- 若使用Maven,Serenity报告默认在
target/site/serenity;若使用Gradle,路径通常为build/reports/serenity,需根据项目构建工具调整路径配置。 - 确保
PathtoPublish等参数与实际生成的报告路径完全匹配。
- 若使用Maven,Serenity报告默认在
检查任务执行顺序
确保归档、发布报告的任务是在Serenity测试/报告生成任务之后执行。如果任务顺序颠倒,报告还未生成就触发归档操作,必然会出现文件缺失错误。检查工作目录文件结构
在流水线中添加一个命令行任务(Windows用CmdLine@2,Linux用Bash@3),放在报告发布任务之前,执行如下命令查看目录结构:# Windows dir $(Build.SourcesDirectory)\target # Linux ls $(Build.SourcesDirectory)/target通过输出确认
site/serenity目录是否存在,以及目录内的文件情况,定位是报告未生成还是路径配置错误。
内容的提问来源于stack exchange,提问作者nosequeweaponer

