For anyone else who may find it helpful, now that my build process is working, here is a simplified run down of my settings and build process:
My first step is to run my tests and generate my a coverage report and test report:
go test "./..." -coverprofile="coverage.out" -covermode=count -json > report.json;
I also added an optional step to generate a go linter report using this 3rd party cli
golangci-lint run ./... --verbose --no-config --out-format checkstyle > golangci-lint.out
My sonar.properties file (which I generate at build time) has these settings in it:
sonar.host.url=https://sonar.xxxxx.com
sonar.projectKey=${PROJECT_KEY}
sonar.sources=${WORKSPACE}
sonar.tests=${WORKSPACE}
sonar.test.inclusions=**/*_test.go,**/testdata/**
Additional settings that I chose to configure from the SonarQube server under the Go settings:
sonar.go.exclusions=**/vendor/**,**/*_mock.go
sonar.go.tests.reportPaths=report.json
sonar.go.coverage.reportPaths=coverage.out
sonar.go.golangci-lint.reportPaths=golangci-lint.out
I also have some branching logic in my build script that depending on GIT_BRANCH and GIT_TAG_NAME values will set one or both of these values in my sonar.properties file:
sonar.projectVersion=${GIT_TAG_NAME}
sonar.branch.name=${GIT_BRANCH}
I then run the sonar scanner:
/opt/sonar-scanner/bin/sonar-scanner
Which then generates output from the scanner that looks like this:
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /var/jenkins_home/jobs/phcommon/workspace/sonar-project.properties
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 3.13.0-170-generic amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: SonarQube server 7.9.2
INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=206ms
INFO: Server id: DACD8EC7-AWYhBymxG4coyY0aj8Nh
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=75ms
INFO: Load/download plugins (done) | time=313ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: phcommon
INFO: Base dir: /var/jenkins_home/jobs/phcommon/workspace
INFO: Working dir: /var/jenkins_home/jobs/phcommon/workspace/.scannerwork
INFO: Load project settings for component key: 'phcommon'
INFO: Load project settings for component key: 'phcommon' (done) | time=26ms
INFO: Load project branches
INFO: Load project branches (done) | time=37ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=19ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=1ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=50ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=581ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: **/*_test.go, **/testdata/**
INFO: Included tests: **/*_test.go, **/testdata/**
INFO: 34 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for go: Sonar way
INFO: ------------- Run sensors on module phcommon
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=23ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=1ms
INFO: Sensor SonarGo [go]
INFO: 17 source files to be analyzed
INFO: Load project repositories
INFO: Load project repositories (done) | time=31ms
INFO: Sensor SonarGo [go] (done) | time=1089ms
INFO: 17/17 source files have been analyzed
INFO: Sensor Go Unit Test Report [go]
INFO: Sensor Go Unit Test Report [go] (done) | time=63ms
INFO: Sensor Go Cover sensor for Go coverage [go]
INFO: Load coverage report from '/var/jenkins_home/jobs/phcommon/workspace/coverage.out'
WARN: File 'git.pursuanthealth.net/go/phcommon/net/apiauth_mock.go' is not included in the project, ignoring coverage
WARN: File 'git.pursuanthealth.net/go/phcommon/net/oauth2_mock.go' is not included in the project, ignoring coverage
WARN: File 'git.pursuanthealth.net/go/phcommon/net/apiclient_mock.go' is not included in the project, ignoring coverage
WARN: File 'git.pursuanthealth.net/go/phcommon/configuration/configuration_mock.go' is not included in the project, ignoring coverage
WARN: File 'git.pursuanthealth.net/go/phcommon/net/httpclient_mock.go' is not included in the project, ignoring coverage
INFO: Sensor Go Cover sensor for Go coverage [go] (done) | time=38ms
INFO: Sensor Import of GolangCI-Lint issues [go]
INFO: Importing /var/jenkins_home/jobs/phcommon/workspace/golangci-lint.out
INFO: Sensor Import of GolangCI-Lint issues [go] (done) | time=15ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: 2 files had no CPD blocks
INFO: Calculating CPD for 15 files
INFO: CPD calculation finished
INFO: Analysis report generated in 153ms, dir size=159 KB
INFO: Analysis report compressed in 66ms, zip size=59 KB
INFO: Analysis report uploaded in 82ms
Hopefully this will be helpful to someone else!