1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SonarqubeのGolang対応

Last updated at Posted at 2020-07-10

元々上記でなんでSonarqubeのVerUp対応をしたかというと、golang対応が6.4では対応していないからである。
https://docs.sonarqube.org/latest/analysis/languages/go/

というわけで対応。sonar-scannerは元々対応済み前提。

sonar.properties
##################################################################
# Properties file for sonar-scanner
# See https://docs.sonarqube.org/display/SONAR/Analysis+Parameters
##################################################################

# Server
sonar.host.url=https://sonarqube.foo.jp/

# Required metadata
#FIXME ここから
sonar.projectKey=golang
sonar.projectName=golang Project
sonar.projectVersion=0.0.1

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
#FIXME ここまで
sonar.sourceEncoding=UTF-8
# sonar.language=py
sonar.go.coverage.reportPaths=reports/coverage.out
sonar.go.tests.reportPaths=reports/test.json

こんな感じのpropertiesファイルを作成して

.PHONY: test
test:
	go test ./... -coverprofile=reports/coverage.out -json > reports/test.json

test時にこんな感じで出力すればOK

仮にJenkinsだとすると、こんな感じのStageを追加すればよい。(尚、startsWithに意味はない)

       stage('Sonarqube Analysis') {
            steps {
                script {
                    // 現状はmasterへのmarge時のみ
                    if (env.BRANCH_NAME.startsWith('master')) {
                        scannerHome = tool 'scanner'
                        withSonarQubeEnv('sonar') {
                            sh "${scannerHome}/bin/sonar-scanner"
                        }
                    } else {
                        echo "Skip Sonarqube analysis."
                    }
                }
	    }
        }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?