# Test-collector plugin: Test Analytics returning error code

**URL:** <https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323>\
**Category:** Test Analytics\
**Created:** [October 25, 2023, 5:38am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323 "2023-10-25T05:38:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 25, 2023, 5:38am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/1 "2023-10-25T05:38:22Z")

</div>

This is what i’m running with:

```auto
steps:
  - label: "Test"
    command:
      - apt-get update
      - apt-get -y install ant
      - ant clean test
    plugins:
      - test-collector#v1.10.0:
          files: "**/test-reports/*.xml"
          format: "junit"

```

The tests run fine, but when it gets to the final section:

```auto
Running plugin test-collector pre-exit hook
$ /buildkite/plugins/github-com-buildkite-plugins-test-collector-buildkite-plugin-v1-10-0/hooks/pre-exit
Uploading '2' files matching '**/test-reports/*.xml'
Uploading './build/test-reports/TEST-HelloTest.xml'...
{
  "message": "Validation failed: Value must be a valid SHA-1 hash"
}
/buildkite/plugins/github-com-buildkite-plugins-test-collector-buildkite-plugin-v1-10-0/hooks/pre-exit: line 181: kill: (3061) - No such process
Uploading './build/test-reports/TEST-TestSortingAlgorithm.xml'...
{
  "message": "Validation failed: Value must be a valid SHA-1 hash"
}

```

Any ideas why it isn’t accepting this - am I missing an environment variable, or configuration on the test-analytics? I have already configured with the correct API Token, and that section of the ui shows ‘Waiting for test data’

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [October 25, 2023, 5:48am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/2 "2023-10-25T05:48:42Z")

</div>

Hello again @Rafe - just saw this and was going to mention the use of the test collector plugin, which it looks like you’ve come across and started to use, which is fantastic 👍

That does look like its relative to the commit SHA not being set correctly and for what the TA API expects. Are you still running these tests using the Buildkite agent image? If its another image entirely, we’d expect something similar to [this](https://buildkite.com/docs/test-analytics/ci-environments#containers-and-test-collectors) (passed in environment variables for the test collector).

Cheers 🙂

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 25, 2023, 5:58am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/3 "2023-10-25T05:58:13Z")

</div>

I’m still using the Buildkite image, this is how I am running it on my local machine:

```auto
docker run \
  -e "BUILDKITE_ANALYTICS_TOKEN=#################" \
  -t \
  --name buildkite-agent-ubuntu \
  buildkite/agent:3-ubuntu start --token "#########################"

```

Should I be telling it which environment variable to look at for the SHA, or passing it in explicitly in the aforementioned yaml?

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 25, 2023, 7:22am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/4 "2023-10-25T07:22:11Z")

</div>

I can see references to setting `run_env[commit_sha]` and others - where should I add that to my yaml?

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [October 25, 2023, 7:34am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/5 "2023-10-25T07:34:23Z")

</div>

No worries - you shouldn’t need to have to pass the variables through to the container like that example: as where the builds are running is where the test collector plugin is also running (specifically, its `pre-exit` hook) which obtains the build’s environment [variables](https://github.com/buildkite-plugins/test-collector-buildkite-plugin/blob/main/hooks/pre-exit#L102-L118) - see specifically `113` where the commit SHA is being obtained from the build context - which you’d not need to explicitly set).

I’ve done a local test on my side (Mac host OS) and all works fine - I pass through an Agent token/Analytics token from my env - pre-set them:

```auto
docker run -it --rm --name buildkite-agent -e "BUILDKITE_ANALYTICS_TOKEN"=$BUILDKITE_ANALYTICS_TOKEN buildkite/agent:3-ubuntu start --token $BUILDKITE_AGENT_TOKEN --tags queue=docker

```

Just wondering - what VCS are you using? Was a case [earlier](https://jira.atlassian.com/browse/BCLOUD-19393?filter=98686&jql=project%20%3D%20BCLOUD%20AND%20resolution%20%3D%20Unresolved%20AND%20text%20~%20%22sha%22%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC) with BitBucket and short SHAs that I wonder if its propagating through here.

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 25, 2023, 7:54am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/6 "2023-10-25T07:54:06Z")

</div>

Currently I’m pulling it down from a test repo that I have on github

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 25, 2023, 8:01am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/7 "2023-10-25T08:01:41Z")

</div>

That was the issue:

![image](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/a/a50cf7b57a55aa4e2a2ca719f0bd758c4d69b67e.png)

It was using HEAD and not converting it over to the actual SHA  
When i replaced the word HEAD with an actual SHA value, it works.

That sounds suspiciously like a bug in the tool, as I can’t see it practical to always make that change in order to get it it work?

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [October 25, 2023, 8:25am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/8 "2023-10-25T08:25:48Z")

</div>

Glad to hear it was the SHA after all!

I’d point you in the direction of using the `resolve-commit-after-checkout` [experiment](https://buildkite.com/docs/agent/v3#experimental-features-resolve-commit-after-checkout) when starting up the container. The`BUILDKITE_COMMIT` initially is sent to the agent as an unresolved reference, in which it sets a [meta data key](https://github.com/buildkite/agent/blob/573d4bf878378c2fb9f0e37de8ae09345a7e6063/bootstrap/bootstrap.go#L1522) with the resolved `COMMIT_SHA` after checkout - and used as `BUILDKITE_COMMIT`. Enabling that experiment will update said variable to the actual SHA after the code is checked out in the first step - and thus to the test collector plugin when its hook is invoked 👍

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 26, 2023, 12:37am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/9 "2023-10-26T00:37:58Z")

</div>

Definitely making progress, I’ve got the agent running with that feature on. I tried a run this morning, with HEAD as the commit, but now the test collector isn’t accepting the results (with a new error):

```auto
test:
    [mkdir] Created dir: /buildkite/builds/1d88a736ad03-1/ETC/TESTTHINGHERE/build/test-reports
    [junit] Running HelloTest
    [junit] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.127 sec
    [junit] Running TestSortingAlgorithm
    [junit] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.018 sec
BUILD FAILED
/buildkite/builds/1d88a736ad03-1/ETC/TESTTHINGHERE/build.xml:31: Tests failed
Total time: 1 second
🚨 Error: The command exited with status 1
user command error: exit status 1
Running plugin test-collector pre-exit hook
$ /buildkite/plugins/github-com-buildkite-plugins-test-collector-buildkite-plugin-v1-10-0/hooks/pre-exit
Uploading '2' files matching '**/test-reports/*.xml'
Uploading './build/test-reports/TEST-HelloTest.xml'...
{"id":"73174528-96ac-408b-aa52-d3d937fc07a6","run_id":"##########################","queued":3,"skipped":0,"errors":[],"run_url":"https://buildkite.com/organizations/ETC/analytics/suites/TESTTHINGHERE/runs/##########################"}/buildkite/plugins/github-com-buildkite-plugins-test-collector-buildkite-plugin-v1-10-0/hooks/pre-exit: line 181: kill: (2159) - No such process
Uploading './build/test-reports/TEST-TestSortingAlgorithm.xml'...
{"id":"##########################","run_id":"##########################","queued":2,"skipped":0,"errors":[],"run_url":"https://buildkite.com/organizations/ETC/analytics/suites/TESTTHINGHERE/runs/##########################"}

```

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [October 26, 2023, 12:54am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/10 "2023-10-26T00:54:52Z")

</div>

Hello again @Rafe!

Great to hear that - this _seems_ to be relative to the first test report thats been uploaded (in particular, `/TEST-HelloTest.xml`. Does those resultant tests in that testcase contain the expected [attributes](https://buildkite.com/docs/test-analytics/importing-junit-xml#mandatory-junit-xml-attributes) (`<classname`\> and \<`name`\> )?. It looks like there wasn’t an error on the second test report though - and seemingly has gone through and processed in your testsuite.

I think it might be worth looking at in more details - feel free to send us a email over at [support@buildkite.com](mailto:support@buildkite.com), and in particular with any sharable test reports that you can (those two from above would be ideal) and the build links to trace the `run_id`s to see what is occurring there.

Cheers 🙂

---

<div class="post-metadata">

**Author:** ![Rafe](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rafe](https://forum.buildkite.community/u/Rafe)\
**Post date:** [October 26, 2023, 2:13am UTC](https://forum.buildkite.community/t/test-collector-plugin-test-analytics-returning-error-code/3323/11 "2023-10-26T02:13:12Z")

</div>

Thanks - I have sent an email off and will see how that goes.
