1
0
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:
yuriy-tereshchuk-sap
2025-08-29 13:15:39 +02:00
committed by GitHub
parent d3a0c8fcad
commit 377ca9ed6e
2 changed files with 10 additions and 2 deletions

View File

@@ -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

View File

@@ -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)