amazon-web-services - AWS CodeBuild 无法生成测试报告“跳过无效文件路径 build/test-results/test”。为什么路径无效?
问题描述
我的 buildspec.yml 是
version: 0.2
phases:
pre_build:
commands:
- cd my-service/
- gradle clean
- echo "prebuild complete!"
build:
commands:
- gradle test
# - gradle bootJar
- echo "prebuild complete!"
post_build:
commands:
- echo "commence post_build"
- cd build/test-results/test
- ls -al
- cd ../../..
- pwd
- echo "post_build complete"
reports:
unit-test-reports:
files:
- '**/*'
base-directory: build/test-results/test
discard-paths: no
artifacts:
files:
- 'build/libs/*.jar'
正如您将看到的,我添加了一些额外的命令,这些命令并不是为了证明路径有效而真正需要的。
输出如下。
Tail logs
Show previous logs
[Container] 2021/01/22 17:08:06 Waiting for agent ping
[Container] 2021/01/22 17:08:08 Waiting for DOWNLOAD_SOURCE
[Container] 2021/01/22 17:08:10 Phase is DOWNLOAD_SOURCE
[Container] 2021/01/22 17:08:10 CODEBUILD_SRC_DIR=/codebuild/output/src353579941/src/github.com/myaccount/myproject
[Container] 2021/01/22 17:08:10 YAML location is /codebuild/output/src353579941/src/github.com/myaccount/myproject/my-service/buildspec.yml
[Container] 2021/01/22 17:08:10 Processing environment variables
[Container] 2021/01/22 17:08:10 Expanded report group name unit-test-reports
[Container] 2021/01/22 17:08:10 Found report group name unit-test-reports
[Container] 2021/01/22 17:08:10 Adding prefix Build-myproject for report group name unit-test-reports
[Container] 2021/01/22 17:08:10 No runtime version selected in buildspec.
[Container] 2021/01/22 17:08:10 Moving to directory /codebuild/output/src353579941/src/github.com/myaccount/myproject
[Container] 2021/01/22 17:08:10 Registering with agent
[Container] 2021/01/22 17:08:10 Phases found in YAML: 3
[Container] 2021/01/22 17:08:10 POST_BUILD: 6 commands
[Container] 2021/01/22 17:08:10 PRE_BUILD: 3 commands
[Container] 2021/01/22 17:08:10 BUILD: 2 commands
[Container] 2021/01/22 17:08:10 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2021/01/22 17:08:10 Phase context status code: Message:
[Container] 2021/01/22 17:08:10 Entering phase INSTALL
[Container] 2021/01/22 17:08:10 Phase complete: INSTALL State: SUCCEEDED
[Container] 2021/01/22 17:08:10 Phase context status code: Message:
[Container] 2021/01/22 17:08:10 Entering phase PRE_BUILD
[Container] 2021/01/22 17:08:10 Running command cd my-service/
[Container] 2021/01/22 17:08:10 Running command gradle clean
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Task :clean UP-TO-DATE
BUILD SUCCESSFUL in 18s
1 actionable task: 1 up-to-date
[Container] 2021/01/22 17:08:32 Running command echo "prebuild complete!"
prebuild complete!
[Container] 2021/01/22 17:08:32 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2021/01/22 17:08:32 Phase context status code: Message:
[Container] 2021/01/22 17:08:32 Entering phase BUILD
[Container] 2021/01/22 17:08:32 Running command gradle test
> Task :compileJava
> Task :processResources
> Task :classes
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
2021-01-22 17:08:56.386 INFO 196 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
BUILD SUCCESSFUL in 24s
4 actionable tasks: 4 executed
[Container] 2021/01/22 17:08:56 Running command echo "prebuild complete!"
prebuild complete!
[Container] 2021/01/22 17:08:56 Phase complete: BUILD State: SUCCEEDED
[Container] 2021/01/22 17:08:56 Phase context status code: Message:
[Container] 2021/01/22 17:08:56 Entering phase POST_BUILD
[Container] 2021/01/22 17:08:56 Running command echo "commence post_build"
commence post_build
[Container] 2021/01/22 17:08:56 Running command cd build/test-results/test
[Container] 2021/01/22 17:08:56 Running command ls -al
total 40
drwxr-xr-x 3 root root 4096 Jan 22 17:08 .
drwxr-xr-x 3 root root 4096 Jan 22 17:08 ..
-rw-r--r-- 1 root root 23616 Jan 22 17:08 TEST-com.myproject.myprojectservice.MyServiceApplicationTests.xml
-rw-r--r-- 1 root root 470 Jan 22 17:08 TEST-com.myproject.myprojectservice.controllers.StatusControllerTest.xml
drwxr-xr-x 2 root root 4096 Jan 22 17:08 binary
[Container] 2021/01/22 17:08:56 Running command cd ../../..
[Container] 2021/01/22 17:08:56 Running command pwd
/codebuild/output/src353579941/src/github.com/myaccount/myproject/my-service
[Container] 2021/01/22 17:08:56 Running command echo "post_build complete"
post_build complete
[Container] 2021/01/22 17:08:56 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2021/01/22 17:08:56 Phase context status code: Message:
[Container] 2021/01/22 17:08:56 Preparing to copy TEST report unit-test-reports
[Container] 2021/01/22 17:08:56 Expanding base directory path: build/test-results/test
[Container] 2021/01/22 17:08:56 Assembling file list
[Container] 2021/01/22 17:08:56 Expanding build/test-results/test
[Container] 2021/01/22 17:08:56 Skipping invalid file path build/test-results/test
[Container] 2021/01/22 17:08:56 No matching base directory path found for build/test-results/test, skipping
[Container] 2021/01/22 17:08:56 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2021/01/22 17:08:56 Phase context status code: Message:
Error in UPLOAD_ARTIFACTS phase: [unit-test-reports: [report files not found in build]]
我正在尝试查看 gradle 生成的 junit 测试结果报告。CodeBuild 似乎能够在 post_build 阶段读取测试报告文件的路径。但是在生成报告时,它说路径无效
该错误声称是 [Container] 2021/01/22 17:08:56 Expanding build/test-results/test [Container] 2021/01/22 17:08:56 Skipping invalid file path build/test-results/test [容器] 2021/01/22 17:08:56 找不到与 build/test-results/test 匹配的基本目录路径,跳过
希望有人能发现一些东西,我已经尝试了我能想到的一切。
解决方案
问题是我的 buildspec.yml 的位置和环境变量 CODEBUILD_SRC_DIR 的值之间的差异
通过运行命令
回声 $CODEBUILD_SRC_DIR
我注意到 CODEBUILD_SRC_DIR 是已签出的存储库的根目录,但我的构建规范不在存储库的根目录中,它是一个目录。
$>repos/my-project/my-api-service/buildspec.yml
我正在使用相对于我的 buildspec.yml 位置的路径
$>repos/my-project/my-api-service/build/test-results/test
所以我只使用构建/测试结果/测试史诗失败
将其更改为相对于 repo my-api-service/build/test-results/test 纯天才的根
现在我有漂亮的junit测试报告
推荐阅读
- javascript - 有没有办法将按钮的名称属性赋予 React 中的对象?
- javascript - 在 react-mentions 包中解析标记
- android - Firebase Analytics 仅显示来自 1 个国家/地区用户的数据
- typescript - 使用 ES6 类 getter / setter 在 TypeScript 中初始化类属性
- reactjs - 基于发布渠道的不同资产 React Native
- aws-sdk-ruby - 如何在 Ruby 2 中复制 AWS AMI?
- php - symfony server:start 总是采用 prod 配置
- javascript - 使用javascript根据用户类型隐藏/取消隐藏文本字段?
- ios - 自定义布局 1 大 2 小单元 UICollectionView
- dax - DAX Power Pivot: "= CONCATENATEX(CALCULATETABLE(" 如何避免重复?