@@ -15,16 +15,20 @@ def getPypiConfig() {
1515
1616def get_sonarqube_unresolved_issues (report_task_file ){
1717 script{
18- if (! fileExists(report_task_file)){
19- error " File not found ${ report_task_file} "
18+ if (! fileExists(report_task_file)){
19+ error " Could not find ${ report_task_file} "
2020 }
2121 def props = readProperties file : report_task_file
22- def response = httpRequest url : props[' serverUrl' ] + " /api/issues/search?componentKeys=" + props[' projectKey' ] + ' &resolved=no'
22+ if (! props[' serverUrl' ] || ! props[' projectKey' ]){
23+ error " Could not find serverUrl or projectKey in ${ report_task_file} "
24+ }
25+ def response = httpRequest url : props[' serverUrl' ] + ' /api/issues/search?componentKeys=' + props[' projectKey' ] + ' &resolved=no'
2326 def outstandingIssues = readJSON text : response. content
2427 return outstandingIssues
2528 }
2629}
2730
31+
2832def getVersion (){
2933 node(){
3034 checkout scm
@@ -275,14 +279,14 @@ def call(){
275279 stage(' Sonarcloud Analysis' ){
276280 options{
277281 lock(' getmarcapi-sonarscanner' )
278- retry(3 )
279282 }
280283 environment{
281284 UV_INDEX_STRATEGY = ' unsafe-best-match'
282285 SONAR_SCANNER_HOME = ' /tmp/sonar'
283286 UV_TOOL_DIR = ' /tmp/uvtools'
284287 UV_PYTHON_INSTALL_DIR = ' /tmp/uvpython'
285288 UV_CACHE_DIR = ' /tmp/uvcache'
289+ SONAR_USER_HOME = ' /tmp/sonar'
286290 }
287291 when{
288292 allOf{
@@ -305,36 +309,23 @@ def call(){
305309 steps{
306310 milestone 1
307311 script{
308- def props = readTOML( file : ' pyproject.toml' )[' project' ]
309- withSonarQubeEnv(installationName :' sonarcloud' , credentialsId : params. SONARCLOUD_TOKEN ) {
310- if (env. CHANGE_ID ){
312+ withSonarQubeEnv(installationName : ' sonarcloud' , credentialsId : params. SONARCLOUD_TOKEN ) {
313+ withCredentials([string(credentialsId : params. SONARCLOUD_TOKEN , variable : ' token' )]) {
311314 sh(
312315 label : ' Running Sonar Scanner' ,
313- script : """ python3 -m venv sonar
314- sonar/bin/pip install --disable-pip-version-check uv
315- trap "rm -rf sonar" EXIT
316- sonar/bin/uvx pysonar-scanner -Dsonar.projectVersion=${ props.version} -Dsonar.buildString=\" ${ env.BUILD_TAG} \" -Dsonar.pullrequest.key=${ env.CHANGE_ID} -Dsonar.pullrequest.base=${ env.CHANGE_TARGET}
317- """
318- )
319- } else {
320- sh(
321- label : ' Running Sonar Scanner' ,
322- script : """ python3 -m venv sonar
323- sonar/bin/pip install --disable-pip-version-check uv
324- trap "rm -rf sonar" EXIT
325- sonar/bin/uvx pysonar-scanner -Dsonar.projectVersion=${ props.version} -Dsonar.buildString=\" ${ env.BUILD_TAG} \" -Dsonar.branch.name=${ env.BRANCH_NAME}
326- """
316+ script : " ./venv/bin/pysonar -t \$ token -Dsonar.projectVersion=${ env.VERSION} -Dsonar.python.xunit.reportPath=./reports/pytest/junit-pytest.xml -Dsonar.python.coverage.reportPaths=./reports/coverage.xml -Dsonar.python.mypy.reportPaths=./logs/mypy.log ${ env.CHANGE_ID ? '-Dsonar.pullrequest.key=$CHANGE_ID -Dsonar.pullrequest.base=$BRANCH_NAME' : '-Dsonar.branch.name=$BRANCH_NAME' } " ,
327317 )
328318 }
329319 }
330- milestone label : ' sonarcloud'
331320 timeout(time : 1 , unit : ' HOURS' ) {
332- def sonarqube_result = waitForQualityGate(abortPipeline : false )
333- if (sonarqube_result. status != ' OK' ) {
334- unstable " SonarQube quality gate: ${ sonarqube_result.status} "
335- }
336- def outstandingIssues = get_sonarqube_unresolved_issues(' .scannerwork/report-task.txt' )
337- writeJSON file : ' reports/sonar-report.json' , json : outstandingIssues
321+ def sonarqubeResult = waitForQualityGate(abortPipeline : false , credentialsId : params. SONARCLOUD_TOKEN )
322+ if (sonarqubeResult. status != ' OK' ) {
323+ unstable " SonarQube quality gate: ${ sonarqubeResult.status} "
324+ }
325+ if (env. BRANCH_IS_PRIMARY ){
326+ writeJSON file : ' reports/sonar-report.json' , json : get_sonarqube_unresolved_issues(' .sonar/report-task.txt' )
327+ recordIssues(tools : [sonarQube(pattern : ' reports/sonar-report.json' )])
328+ }
338329 }
339330 }
340331 }
0 commit comments