1

my buildspec.yml is

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'

as you will see I added some additional commands that are not really necessary just to prove that the path is valid.

output is below.

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]]

I am trying to view the junit test results report generated by gradle. CodeBuild seems able to read the path to the test report files in the post_build phase. But when it comes to generating the report, it says the path is invalid

the error claims to be [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

Hope someone can spot something, I have tried everything I can think of.

1 Answer 1

3

The problem was a difference between the location of my buildspec.yml and the value of environemnet variable CODEBUILD_SRC_DIR

by running a command

echo $CODEBUILD_SRC_DIR

I noticed that CODEBUILD_SRC_DIR is the root of the repo that was checked out but my buildspec was not in the root of the repo, it was one directory down.

$>repos/my-project/my-api-service/buildspec.yml

i was using paths relative to the location of my buildspec.yml

$>repos/my-project/my-api-service/build/test-results/test

so i was using just build/test-results/test epic fail

changed it to be relative to root of repo my-api-service/build/test-results/test pure genius

now I have beautiful junit test reports

Sign up to request clarification or add additional context in comments.

1 Comment

This was it. Thanks Rory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.