You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
fix(sonar): Fix null value for errors entry in sonarscan report (#5459)
Co-authored-by: Yuriy.Tereshchuk <astro.lutsk.aa@gmail.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d3a0c8fcad
commit
377ca9ed6e
@@ -252,7 +252,7 @@ func runSonar(config sonarExecuteScanOptions, client piperhttp.Downloader, runne
|
||||
}
|
||||
// fetch number of issues by severity
|
||||
issueService := SonarUtils.NewIssuesService(serverUrl, config.Token, taskReport.ProjectKey, config.Organization, config.BranchName, config.ChangeID, apiClient)
|
||||
var categories []SonarUtils.Severity
|
||||
var categories = make([]SonarUtils.Severity, 0)
|
||||
influx.sonarqube_data.fields.blocker_issues, err = issueService.GetNumberOfBlockerIssues(&categories)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -180,8 +181,15 @@ func TestRunSonar(t *testing.T) {
|
||||
defer os.Setenv("SONAR_SCANNER_OPTS", "")
|
||||
// test
|
||||
err := runSonar(options, &mockDownloadClient, &mockRunner, apiClient, &mock.FilesMock{}, &sonarExecuteScanInflux{})
|
||||
// assert
|
||||
assert.NoError(t, err)
|
||||
// load sonarscan report file
|
||||
reportFile, err := os.ReadFile(filepath.Join(tmpFolder, "sonarscan.json"))
|
||||
assert.NoError(t, err)
|
||||
var reportData SonarUtils.ReportData
|
||||
err = json.Unmarshal(reportFile, &reportData)
|
||||
assert.NoError(t, err)
|
||||
// assert
|
||||
assert.NotNil(t, reportData.Errors)
|
||||
assert.Contains(t, sonar.options, "-Dsonar.projectVersion=1")
|
||||
assert.Contains(t, sonar.options, "-Dsonar.organization=SAP")
|
||||
assert.Contains(t, sonar.environment, "SONAR_HOST_URL="+sonarServerURL)
|
||||
|
Reference in New Issue
Block a user