@@ -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
@@ -287,14 +291,16 @@ def call(){
287291 stage(' Sonarcloud Analysis' ){
288292 options{
289293 lock(' getmarcapi-sonarscanner' )
290- retry(3 )
291294 }
292295 environment{
293296 UV_INDEX_STRATEGY = ' unsafe-best-match'
294297 SONAR_SCANNER_HOME = ' /tmp/sonar'
295298 UV_TOOL_DIR = ' /tmp/uvtools'
296299 UV_PYTHON_INSTALL_DIR = ' /tmp/uvpython'
297300 UV_CACHE_DIR = ' /tmp/uvcache'
301+ SONAR_USER_HOME = ' /tmp/sonar'
302+ VERSION = " ${ readTOML( file: 'pyproject.toml')['project'].version} "
303+
298304 }
299305 when{
300306 allOf{
@@ -317,36 +323,23 @@ def call(){
317323 steps{
318324 milestone 1
319325 script{
320- def props = readTOML( file : ' pyproject.toml' )[' project' ]
321- withSonarQubeEnv(installationName :' sonarcloud' , credentialsId : params. SONARCLOUD_TOKEN ) {
322- if (env. CHANGE_ID ){
326+ withSonarQubeEnv(installationName : ' sonarcloud' , credentialsId : params. SONARCLOUD_TOKEN ) {
327+ withCredentials([string(credentialsId : params. SONARCLOUD_TOKEN , variable : ' token' )]) {
323328 sh(
324329 label : ' Running Sonar Scanner' ,
325- script : """ python3 -m venv sonar
326- sonar/bin/pip install --disable-pip-version-check uv
327- trap "rm -rf sonar" EXIT
328- 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}
329- """
330- )
331- } else {
332- sh(
333- label : ' Running Sonar Scanner' ,
334- script : """ python3 -m venv sonar
335- sonar/bin/pip install --disable-pip-version-check uv
336- trap "rm -rf sonar" EXIT
337- sonar/bin/uvx pysonar-scanner -Dsonar.projectVersion=${ props.version} -Dsonar.buildString=\" ${ env.BUILD_TAG} \" -Dsonar.branch.name=${ env.BRANCH_NAME}
338- """
330+ 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' } " ,
339331 )
340332 }
341333 }
342- milestone label : ' sonarcloud'
343334 timeout(time : 1 , unit : ' HOURS' ) {
344- def sonarqube_result = waitForQualityGate(abortPipeline : false )
345- if (sonarqube_result. status != ' OK' ) {
346- unstable " SonarQube quality gate: ${ sonarqube_result.status} "
347- }
348- def outstandingIssues = get_sonarqube_unresolved_issues(' .scannerwork/report-task.txt' )
349- writeJSON file : ' reports/sonar-report.json' , json : outstandingIssues
335+ def sonarqubeResult = waitForQualityGate(abortPipeline : false , credentialsId : params. SONARCLOUD_TOKEN )
336+ if (sonarqubeResult. status != ' OK' ) {
337+ unstable " SonarQube quality gate: ${ sonarqubeResult.status} "
338+ }
339+ if (env. BRANCH_IS_PRIMARY ){
340+ writeJSON file : ' reports/sonar-report.json' , json : get_sonarqube_unresolved_issues(' .sonar/report-task.txt' )
341+ recordIssues(tools : [sonarQube(pattern : ' reports/sonar-report.json' )])
342+ }
350343 }
351344 }
352345 }
0 commit comments