SonarCloud code coverage % for GoTest files using Bitbucket Pipeline

Hi community,

I’m looking for an help that I’m unable to get the code coverage % in Sonar Cloud for Go Test Files(main_test.go) using the below Bitbucket pipeline script.
Script to Run Go Test

  • cd src/workspace
  • go build -v -o workspace
  • go test -v -short -coverprofile workspace_coverage.out ./…
  • go tool cover -func=“workspace_coverage.out”

Below is the result of go tool command

Bitbucket Sonar Successfull Result


  • pipe: sonarsource/sonarcloud-scan:1.2.1
    EXTRA_ARGS: ‘-X -Dsonar.sources=. -Dsonar.c.file.suffixes=- -Dsonar.cpp.file.suffixes=- -Dsonar.objc.file.suffixes=- -Dsonar.test=src/workspace/_test.go -Dsonar.test.inclusions=src/workspace/_test.go -Dsonar.go.coverage.reportPaths=src/workspace/workspace_coverage.out’

Code Coverage details in Sonar Cloud
Overview of Code Coverage

When i cross check with bitbucket pipeline artifact for sonar scanner it throws an warning message as below.
19:17:34.236 DEBUG: Resolving file workspace/main.go using relative path
19:17:34.237 WARN: File ‘workspace/main.go’ is not included in the project, ignoring coverage

Will be waiting for your response.

Sanjay A

Hi Community,

Can anyone help me out with the answer for the above problem.

Sanjay A