Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

How to obtain the SonarQube taskId / report URL in Jenkins Pipeline?

I have intergrated Sonarqube in Jenkins Pipeline, it working as below define:

        stage('static check') {
           steps {
               echo "starting codeAnalyze with SonarQube......"
               //sonar:sonar.QualityGate should pass
               withSonarQubeEnv('sonar') {
                 sh "mvn -f pom.xml clean compile sonar:sonar -U"
               }
               script {
               timeout(10) { 
                   def qg = waitForQualityGate() 
                       if (qg.status != 'OK') {
                         echo "failure: ${qg.status}"
                         
                         # Plan to send notify to Slack, But can NOT to obtain the Sonar report URL or TaskId
                         
                       }
                   }
               }
           }
       }

Plan to send corresponding notify to Slack, But can NOT to obtain the Sonar report URL or TaskId

And found some guys suggest that use BUILD_LOG_REGEX: SonarQube result URL: ${BUILD_LOG_REGEX, regex=".*ANALYSIS SUCCESSFUL, you can browse (.*)", showTruncatedLines=false, substText="$1"}, but this only working in Email Extension Plugin.

Another suggest is compose the report URL by this: ProjectURL = host + "/dashboard?id=" + ProjectID, and we not easy to get the ProjectID, since the projectID is compose from Pom.xml as: groupId:artifactId.

Maybe there is some easy way to get the Sonar TaskId or Report URL, Especially whether there is the waitForQualityGate() or other method will return the Sonar TaskId or Report URL ?

question from:https://stackoverflow.com/questions/65880598/how-to-obtain-the-sonarqube-taskid-report-url-in-jenkins-pipeline

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can see the report by reading the file ./target/sonar/report-task.txt

Using def getURL = readProperties file: './target/sonar/report-task.txt'

and extract by calling something like this ${getURL['dashboardUrl']} which is will give url of report. also that above file have taskId.

so it should like this

def qg = waitForQualityGate() 
 if (qg.status != 'OK') {
 echo "failure: ${qg.status}"
 def getURL = readProperties file: './target/sonar/report-task.txt

 Add your slackmsg here use in that ${getURL['dashboardUrl']}

 }
                     

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...