Test Coverage report failure

Hi,
I have a Buildkite step that runs test and reports the coverage.
The ouput/error of the step is redirected into a code_coverage.txt which is passed as an artifact to the next Buildkite steps.

The coverage report is successfully generated and the steps outputs the coverage report into the terminal.

However, if the same coverage report is redirected using the &> operator into the code_coverage.txt file, it is fails to redirect the output of the same into the file and the file is empty.

Working command → make test-coverage MIN_COVERAGE=85 GO_BIN_PATH=/go/bin

New command that does not work → make test-coverage MIN_COVERAGE=85 GO_BIN_PATH=/go/bin &> code_coverage.txt

Can you pls lmk why is this failure happening when I use the &> operator in Buildkite?

Step code :

  - label: ":shrek: Run tests & report coverage"
    key: "an-test-coverage"
    artifact_paths:
      - "code_coverage.txt"
    plugins:
      - docker#v5.9.0:
          image: "golang:1.21.1"
          volumes:
            # Necessary for docker-in-docker testcontainers
            - "/var/run/docker.sock:/var/run/docker.sock"
          network: "host"
          command:
            - "sh"
            - "-c"
            - "cd nest && make test-coverage MIN_COVERAGE=85 GO_BIN_PATH=/go/bin &> code_coverage.txt"

Hey @fansari1 :wave:

I took a deep dive into this issue and tried to reproduce it on my end—no luck so far in hitting the same snag.

Initially, I thought it might be because of the &> operator, which is specific to Bash. Since you’re usingsh -c, it’s possible that sh doesn’t handle &> the same way. But even with that theory, I wasn’t able to trigger any errors myself.

If you can grab a screenshot of the actual error or, even better, share the build link with us at support@buildkite.com, that would definitely help us dig deeper and get to the bottom of this!

Hi @stephanie.atte

You’re right.
THe issue was with the &> filename operator.
The alternative operator in sh is > filename 2>&1

Thanks a lot for your help !!

Updated code :

- label: ":shrek: Run tests & report coverage"
    key: "an-test-coverage"
    artifact_paths:
      - "code_coverage.txt"
    plugins:
      - docker#v5.9.0:
          image: "golang:1.21.1"
          volumes:
            # Necessary for docker-in-docker testcontainers
            - "/var/run/docker.sock:/var/run/docker.sock"
          network: "host"
          command:
            - "sh"
            - "-c"
            - "cd nest && make test-coverage MIN_COVERAGE=85 GO_BIN_PATH=/go/bin > code_coverage.txt 2>&1" ```
2 Likes