[RFF] SonarQube Scanner for Jenkins 2.6

2,851 views
Skip to first unread message

Julien HENRY

unread,
Feb 22, 2017, 10:02:24 AM2/22/17
to jenkin...@googlegroups.com, SonarQube
Hi,

I would like to collect feedback before the upcoming release of the SonarQube Scanner for Jenkins.

The main new feature is that we introduced a new pipeline step that would put the pipeline in pause until SonarQube analysis is finished, and the step will then give access to the quality gate status. You can then implement any logic you want.

Example:
      stage("build & SonarQube analysis") {
          node {
              withSonarQubeEnv('My SonarQube Server') {
                 sh 'mvn clean package sonar:sonar'
              }    
          }
      }
      
      stage("Quality Gate"){
          timeout(time: 1, unit: 'HOURS') {
              def qg = waitForQualityGate()
              if (qg.status != 'OK') {
                  error "Pipeline aborted due to quality gate failure: ${qg.status}"
              }
          }
      }

You can test using this artifact:

Documentation is available directly on the step in the pipeline snippet generator.

Feedback period is open until Friday.

Regards,

Julien

Arnaud Héritier

unread,
Feb 22, 2017, 10:53:09 AM2/22/17
to jenkin...@googlegroups.com, SonarQube
Myself I like it !!

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEpf977L%3DxpzxaBZ0qMqOPO2CDQDEym7ue8MUGimhM2sQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
-----
Arnaud Héritier
Mail/GTalk: aheritier AT gmail DOT com
Twitter/Skype : aheritier

Tim Downey

unread,
Feb 22, 2017, 12:13:09 PM2/22/17
to Jenkins Developers, sona...@googlegroups.com
Hi Julien,

This is terrific, but I'm having issues.  I'm trying to use this within a pipeline model definition build.  I'm struggling with `waitForQualityGate`.  Wherever I put it, I'm getting an exception.  I've tried the `waitForQualityGate` both in the same and in separate stages.  Any suggestions?

java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. If you are not using the 'withSonarQubeEnv' wrapper to run your analysis, you have to pass the attributes manually to this step.
        at org
.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:127)
        at org
.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:107)

        stage('sonar-build') {

            steps {
                script {
                    withSonarQubeEnv('VantageSonar') {
                        sh 'mvn clean package sonar:sonar'

                        def qg = waitForQualityGate()
                        if (qg.status != 'OK') {
                          error "Pipeline aborted due to quality gate failure: ${qg.status}"
                        }
                    }
                }
            }
        }Enter code here...

Julien HENRY

unread,
Feb 24, 2017, 11:42:24 AM2/24/17
to SonarQube, jenkin...@googlegroups.com, timothy...@gmail.com
Hi Tim,

The step waitForQualityGate has to be used outside withSonarQubeEnv. Also remember that the purpose is to not occupy a Jenkins executor during the wait, so your sh step should be in a node, but not the waitForQualityGate.

HTH

Julien

georg....@netcentric.biz

unread,
Feb 28, 2017, 8:02:25 AM2/28/17
to SonarQube, jenkin...@googlegroups.com
Hi Julien, 

this feature is nice but it has been easily possible to achieve the same with https://github.com/SonarQubeCommunity/sonar-build-breaker (or https://github.com/AmadeusITGroup/sonar-stash that we use ATM). 

A lot more important would be the long-standing issue https://jira.sonarsource.com/browse/SONAR-6763 - any news when quality gates on incremental (or if not incremental, at least on "non-server-side-saving") sonar runs will be possible?

Best Regards
Georg

Fabrice Bellingard

unread,
Feb 28, 2017, 9:25:39 AM2/28/17
to georg....@netcentric.biz, SonarQube, jenkin...@googlegroups.com
On Tue, Feb 28, 2017 at 2:02 PM, <georg....@netcentric.biz> wrote:
Hi Julien, 

this feature is nice but it has been easily possible to achieve the same with https://github.com/SonarQubeCommunity/sonar-build-breaker (or https://github.com/AmadeusITGroup/sonar-stash that we use ATM). 

This is not exactly true. When you're using this community plugin, your job is stuck and you're consuming a Jenkins executor (because the plugin is polling the SonarQube server) until the report is processed.
With the new feature, you can write your Jenkins pipeline so that you're not using any executor once the report has been sent to the server. It's SonarQube which will notify Jenkins (using a webhook) that the report has been processed and the QG is available. This is much better, and allows you to scale more w/o risking to have your Jenkins fully frozen because of the build-breaker plugin.

 
A lot more important would be the long-standing issue https://jira.sonarsource.com/browse/SONAR-6763 - any news when quality gates on incremental (or if not incremental, at least on "non-server-side-saving") sonar runs will be possible?

This is part of the effort we're going to start on the first-class citizen support of branches and P/R in SonarQube. So no worries, we don't forget this topic.


Best regards,

Fabrice BELLINGARD | SonarSource
SonarQube & SonarLint Product Manager
http://sonarsource.com
 
Best Regards
Georg

On Wednesday, 22 February 2017 16:02:24 UTC+1, Julien HENRY wrote:
Hi,

I would like to collect feedback before the upcoming release of the SonarQube Scanner for Jenkins.

The main new feature is that we introduced a new pipeline step that would put the pipeline in pause until SonarQube analysis is finished, and the step will then give access to the quality gate status. You can then implement any logic you want.

Example:
      stage("build & SonarQube analysis") {
          node {
              withSonarQubeEnv('My SonarQube Server') {
                 sh 'mvn clean package sonar:sonar'
              }    
          }
      }
      
      stage("Quality Gate"){
          timeout(time: 1, unit: 'HOURS') {
              def qg = waitForQualityGate()
              if (qg.status != 'OK') {
                  error "Pipeline aborted due to quality gate failure: ${qg.status}"
              }
          }
      }

You can test using this artifact:

Documentation is available directly on the step in the pipeline snippet generator.

Feedback period is open until Friday.

Regards,

Julien

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/cd1b94a5-4fe1-47ac-b4ee-54db83ef8499%40googlegroups.com.

Laurent Tourreau

unread,
Mar 2, 2017, 1:58:37 PM3/2/17
to SonarQube, georg....@netcentric.biz, jenkin...@googlegroups.com
Hi all

I am trying this wonderful feature in a Jenkins Pipeline. The webhook is not able to communicate to Jenkins (i get HTTP 403) as consequence the answer is not sent to Jenkins and it wait until the timeout. Here is the REST API result:


api
/webhooks/deliveries result:

{"deliveries":[{"id":"AVqQTJiMvUKPnZt1PZie","componentKey":"com.mycompany:web-app","ceTaskId":"AVqQTI00uNSR7Z9AqVMA","name":"Jenkins
ATI"
,"url":"http://jenkins.mycompany.com:8080/jenkins/sonarqube-webhook/","at":"2017-03-02T19:33:43+0100","success":false,"httpStatus":403,"durationMs":7}]}


api/webhooks/delivery result:

{"delivery":{"id":"AVqQTJiMvUKPnZt1PZie","componentKey":"com.mycompany:web-app","ceTaskId":"AVqQTI00uNSR7Z9AqVMA","name":"Jenkins
ATI"
,"url":"http://jenkins.mycompany.com:8080/jenkins/sonarqube-webhook/","at":"2017-03-02T19:33:43+0100","success":false,"httpStatus":403,"durationMs":7,"payload":"{\"taskId\":\"AVqQTI00uNSR7Z9AqVMA\",\"status\":\"SUCCESS\",\"analysedAt\":\"2017-03-02T19:33:34+0100\",\"project\":{\"key\":\"com.mycompany:web-app\",\"name\":\"com.mycompany:web-app\"},\"qualityGate\":{\"name\":\"SonarQube
way\",\"status\":\"OK\",\"conditions\":[{\"metric\":\"new_security_rating\",\"operator\":\"GREATER_THAN\",\"value\":\"1\",\"status\":\"OK\",\"onLeakPeriod\":true,\"errorThreshold\":\"1\"},{\"metric\":\"new_reliability_rating\",\"operator\":\"GREATER_THAN\",\"value\":\"1\",\"status\":\"OK\",\"onLeakPeriod\":true,\"errorThreshold\":\"1\"},{\"metric\":\"new_maintainability_rating\",\"operator\":\"GREATER_THAN\",\"value\":\"1\",\"status\":\"OK\",\"onLeakPeriod\":true,\"errorThreshold\":\"1\"},{\"metric\":\"new_coverage\",\"operator\":\"LESS_THAN\",\"status\":\"NO_VALUE\",\"onLeakPeriod\":true,\"errorThreshold\":\"80\"}]},\"properties\":{}}"
}}


I have disabled Jenkins security -> same result.
The webhook http://jenkins.mycompany.com:8080/jenkins/sonarqube-webhook is configured on Configuration->General Settings -> Webhooks tab

How can we find the root cause?

Regards

Laurent TOURREAU

Laurent Tourreau

unread,
Mar 3, 2017, 5:03:39 AM3/3/17
to SonarQube, georg....@netcentric.biz, jenkin...@googlegroups.com
Hi SonarQube Team

I find the culprit : the corporate proxy.
We have configured http.proxy variables in sonar.properties (to allow the plugin upgrade from Update Center).
The problem is by setting this our Jenkins instance cannot be reachable since it use the proxy.

I disable the proxy settings (toggling comment on them) -> it works SonarQube is able to send the webhook request. I can see Jenkins receiving it.

We should use proxy exclusion variable but such variable doesn't exist in sonar.properties:

http.proxyExclude
https.proxyExclude

Can you book a JIRA to add exclusion for proxy (HTTP and HTTPS)?

Regards

Laurent TOURREAU

Julien HENRY

unread,
Mar 3, 2017, 7:36:30 AM3/3/17
to Jenkins Developers, sona...@googlegroups.com
Hi Georg,


Le mardi 28 février 2017 14:02:33 UTC+1, georg....@netcentric.biz a écrit :
Hi Julien, 

this feature is nice but it has been easily possible to achieve the same with https://github.com/SonarQubeCommunity/sonar-build-breaker

Build breaker was using polling, which has several drawback. That's why we were not supporting it. Also here you get the status in your pipeline script. You can decide to implement any logic, not always fail the build. For example use the input step to ask for a manual user confirmation before moving the pipeline forward.
I don't consider that reporting issues on a pull request and getting quality gate status in your Jenkins pipeline are similar features.
 

A lot more important would be the long-standing issue https://jira.sonarsource.com/browse/SONAR-6763 - any news when quality gates on incremental (or if not incremental, at least on "non-server-side-saving") sonar runs will be possible?

That's a different topic, so I will not respond here.

arvid...@jayway.com

unread,
Mar 13, 2017, 8:29:12 AM3/13/17
to SonarQube, jenkin...@googlegroups.com, timothy...@gmail.com
Hi Julien,

I am facing exactly the same behaviour as Tim describes, the difference with my setup is that it works for a single jenkins server setup but not in a jenkins master/slave environment. As soon as I try to run my pipeline script on the master/slave jenkins I get the IllegalStateException!  waitForQualityGate fails since it cannot find either server or task id from the previous analysis.

Is there any workaround for this?

brg
Arvid

Arvid Huss

unread,
Mar 14, 2017, 5:11:42 AM3/14/17
to Jenkins Developers, sona...@googlegroups.com, timothy...@gmail.com
Hi Julien,

I am facing exactly the same behaviour as Tim describes, the difference with my setup is that it works for a single Jenkins server setup but not in a Jenkins master/slave environment. When I run my pipeline script on the master/slave jenkins I get the IllegalStateException!  waitForQualityGate fails since it cannot find either server or task id from the previous analysis. 

Is there any workaround for this?

brg
Arvid

Julien HENRY

unread,
Mar 14, 2017, 5:25:58 AM3/14/17
to jenkin...@googlegroups.com, SonarQube, timothy...@gmail.com
Hi Arvid,

Could you please share your pipeline script? Remember that waitForQualityGate should be used after/outside withSonarQubeEnv closure.

withSonarQubeEnv() {
   xxx
}
def qg = waitForQualityGate()

++

Julien

jan....@thanksys.com

unread,
Mar 15, 2017, 6:11:30 AM3/15/17
to SonarQube, jenkin...@googlegroups.com, timothy...@gmail.com
*Should* the waitForQualityGate be outside a node, or *must* it be outside of a node? We have some existing scripts which use a single node scope for the whole script, and would like to integrate the quality gate with minimal changes. The extra wait time is no issue at the moment.

We also have the "Unable to get task id" issue, not sure whether this is related? It's also not clear to me yet how I should start debugging it (I'm looking at the Java code of the plugin, but I'm not sure how many structures I can access in my Jenkinsfile to print their values, e.g. to get the SonarAnalysisAction).

Regards,

Jan Fabry

Julien HENRY

unread,
Mar 17, 2017, 11:59:08 AM3/17/17
to SonarQube, jenkin...@googlegroups.com, timothy...@gmail.com, jan....@thanksys.com
Hi Jan,


Le mercredi 15 mars 2017 11:11:30 UTC+1, jan....@thanksys.com a écrit :
*Should* the waitForQualityGate be outside a node, or *must* it be outside of a node? We have some existing scripts which use a single node scope for the whole script, and would like to integrate the quality gate with minimal changes. The extra wait time is no issue at the moment.

It *should* be outside a node
but
It *must* be outside the withSonarQubeEnv closure (since collecting analysis id is done at the end of the closure).

I was not able to reproduce the problem, so please try to produce a sample reproducer (with precise Jenkins version, number of slaves, and of course the pipeline script).

Thanks

Julien

Idan Adar

unread,
Mar 20, 2017, 6:46:52 PM3/20/17
to SonarQube, jenkin...@googlegroups.com
I'd like to join the growing number of users unable to make this work...

Jenkins 2.5
SonarQube 6.2
1 master and 1 slave machine

The following fails with: java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.


stage ("SonarQube analysis") {
     steps {
        script {
           STAGE_NAME = "SonarQube analysis"

           if (BRANCH_NAME == "develop") {
              echo "In 'develop' branch, don't analyze."
           }
           else { // this is a PR build, run sonar analysis
              withSonarQubeEnv("SonarGate") {
                 sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"   
              }
           }
        }
     }
  }

  stage ("SonarQube Gatekeeper") {
     steps {
        script {
           STAGE_NAME = "SonarQube Gatekeeper"

           if (BRANCH_NAME == "develop") {
              echo "In 'develop' branch, skip."
           }
           else { // this is a PR build, fail on threshold spill
              def qualitygate = waitForQualityGate()
              if (qualitygate.status != "OK") {
                 error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
              } 
           }
        }
     }
  }


I did also post more information on StackOverflow, but given that there hasn't been any interaction there, I'll just mention here as well...

johan...@gmail.com

unread,
Mar 20, 2017, 11:10:09 PM3/20/17
to SonarQube, jenkin...@googlegroups.com
I have the same issue. Wasn't able to find a lot of things online in order to solve it though =/


Thanks for helping :)

Julien HENRY

unread,
Mar 21, 2017, 4:29:36 AM3/21/17
to jenkin...@googlegroups.com, SonarQube
Hi,

Can you tell me what is this "steps" keyword? When I try to use it I get 
NoSuchMethodError: No such DSL method 'steps'

Also, what is the point of the script block?

In short, what happen if you simplify your script to:

stage ("SonarQube analysis") {
           STAGE_NAME = "SonarQube analysis"

           if (BRANCH_NAME == "develop") {
              echo "In 'develop' branch, don't analyze."
           }
           else { // this is a PR build, run sonar analysis
              withSonarQubeEnv("SonarGate") {
                 sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"   
              }
           }
  }

  stage ("SonarQube Gatekeeper") {
           STAGE_NAME = "SonarQube Gatekeeper"

           if (BRANCH_NAME == "develop") {
              echo "In 'develop' branch, skip."
           }
           else { // this is a PR build, fail on threshold spill
              def qualitygate = waitForQualityGate()
              if (qualitygate.status != "OK") {
                 error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
              } 
           }
  }


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/20c139a7-1e33-48d0-a9ae-ca5512f28785%40googlegroups.com.

Tim Downey

unread,
Mar 21, 2017, 7:24:00 AM3/21/17
to jenkin...@googlegroups.com, SonarQube
Hi Julien,

'steps' is part of declarative pipeline which is becoming the recommendation from the Jenkins folks on how to write your Jenkinsfiles.


Tim

Julien HENRY

unread,
Mar 21, 2017, 8:41:16 AM3/21/17
to jenkin...@googlegroups.com, SonarQube
OK, I did a test with a declarative pipeline, and it works fine. Here is my sample pipeline. Can you try on your own instance and see how it goes (you have to replace bold values by your own)?

pipeline {
    agent none
    stages {
        stage("build & SonarQube Scan") {
            agent any
            steps {
              git changelog: false, poll: false, url: 'https://github.com/SonarQubeCommunity/sonar-clirr.git'
              script {
                  withEnv(["JAVA_HOME=${ tool '8u121' }", "PATH+MAVEN=${tool '3.3.9'}/bin:${env.JAVA_HOME}/bin"]) {
                    withSonarQubeEnv('localhost') {
                       sh 'mvn clean package sonar:sonar -DskipTests'
                    }    
                  }
              }
            }
        }
        
        stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
                    script  {

Jan Fabry

unread,
Mar 21, 2017, 2:33:20 PM3/21/17
to Julien HENRY, jenkin...@googlegroups.com, SonarQube
Hello Julien,

Is it possible that this only works for Maven projects?

I was able to run your example, and then I tried the Spring Boot "Getting started" example (from https://github.com/spring-guides/gs-spring-boot/tree/master/complete). If I build it via Maven it works, if I do it via Gradle it doesn't.

I tried it on Jenkins 2.48 and Jenkins 2.51, with SonarQube Scanner plugin 2.6. I tested this with a multibranch project, with the Jenkinsfile in the repository. If you want to try it yourself you have to change the complete/build.gradle file to include the SonarQube plugin.

This was my Jenkinsfile (Gradle version):

#!groovy

pipeline {
    agent none
    stages {
        stage("build & SonarQube Scan") {
            agent any
            steps {
              checkout scm
              script {
                dir('complete') {
                  withEnv(["JAVA_HOME=${ tool '<Java tool>' }", "PATH+JAVA=${env.JAVA_HOME}/bin"]) {
                    withSonarQubeEnv('<SonarQube environment>') {
                       sh './gradlew sonarqube'
                    }    
                  }
                }
              }
            }
        }
        
        stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
                    script  {
                        def qg = waitForQualityGate()
                        if (qg.status != 'OK') {
                            error "Pipeline aborted due to quality gate failure: ${qg.status}"
                        }
                    }
                }
            }
        }
    }
}

Let me know if  you want any other tests.

Regards,

Jan Fabry

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/z_K_wz_8Vw8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/CAD9wyxEf%2BR_tbPQwfCUYnrw8DW5ftePsfsP%2B5QLzEXSW4z4nuA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Jan Fabry
Operations
+32 484 03 89 15

Julien HENRY

unread,
Mar 21, 2017, 3:45:43 PM3/21/17
to Jan Fabry, jenkin...@googlegroups.com, SonarQube
Hi Jan,

I think I understand why it doesn't work with Gradle.

2017-03-21 19:32 GMT+01:00 Jan Fabry <jan....@thanksys.com>:
Let me know if  you want any other tests.

Please try to run sh './gradlew --info sonarqube' and I guess it should work.

++

Julien

Jan Fabry

unread,
Mar 21, 2017, 4:19:32 PM3/21/17
to Julien HENRY, jenkin...@googlegroups.com, SonarQube
Boom! It works! And the people who run sonar-scanner manually must
probably also make sure that the relevant lines are logged, so they
can be picked up by the plugin?

I have been wondering from the start how the plugin managed to get
that information and pass it to the next step, but now I think I
finally found it: class hudson.plugins.sonar.utils.SonarUtils, methods
extractReportTask and extractSonarProjectURLFromLogs. So for anyone
else that has this issue, read that code and make sure the magic lines
"Working dir: <dir with report-task.txt>" and "ANALYSIS SUCCESSFUL,
you can browse <sonarqube url>" are in your build output!

Would it make sense to add a workflow step that allows us to tell the
plugin this path and the URL manually, for builds that can't add this
to the regular build output?

Regards,

Jan

Jan Fabry

unread,
Mar 22, 2017, 3:38:35 AM3/22/17
to Julien HENRY, jenkin...@googlegroups.com, SonarQube
Hello Julien,

This does not work if you run it on a slave. If I change the "agent
any" to "agent { label: "some-slave" }", then it fails for me. My
setup has one master (Linux) and one slave (macOS). Both can reach the
SonarQube server. The badge in the build history does link to the
SonarQube project, so that part is parsed successfully.

(This is exactly Johann's case - I misread it earlier and thought it
was about the necessary output missing, but his script does work on a
master node, just not on a slave)

Regards,

Jan Fabry

On 21 March 2017 at 13:40, Julien HENRY <julien...@sonarsource.com> wrote:
>>>> jenkinsci-de...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/jenkinsci-dev/20c139a7-1e33-48d0-a9ae-ca5512f28785%40googlegroups.com.
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Jenkins Developers" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> jenkinsci-de...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxENJfUfUhgkNL9hCLXtgig8%2B%2BBQfrcKqiwMsRFu_FXErQ%40mail.gmail.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Jenkins Developers" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> jenkinsci-de...@googlegroups.com.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "SonarQube" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sonarqube/z_K_wz_8Vw8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sonarqube+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sonarqube/CAD9wyxEf%2BR_tbPQwfCUYnrw8DW5ftePsfsP%2B5QLzEXSW4z4nuA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Julien HENRY

unread,
Mar 22, 2017, 3:52:26 AM3/22/17
to Jan Fabry, jenkin...@googlegroups.com, SonarQube
Hi Jan,

Thanks for confirming my guess about log parsing. I think we need to provide a more robust solution for Gradle users. sonar-scanner users should be unaffected since logs should be there.

Still we need to understand the master/slave issue. As I said, I already tried the master/slave scenario (ok, the slave is on the same machine, but I don't see why this would affect the process).

After the end of the withSonarQubeEnv closure (and assuming log parsing was working), we should have collected server URL and taskId, and stored them in a Jenkins "action". It should be visible in the build.xml of the build. Something like:

<hudson.plugins.sonar.action.SonarAnalysisAction plugin="so...@2.7-SNAPSHOT">
      <installationName>localhost</installationName>
      <ceTaskId>AVrxNskUNRuu9JoQMGou</ceTaskId>
      <isNew>true</isNew>
      <isSkipped>false</isSkipped>
</hudson.plugins.sonar.action.SonarAnalysisAction>

Can you confirm that you see this in your master/slave test?

Thanks

Julien

Jan Fabry

unread,
Mar 22, 2017, 4:21:43 AM3/22/17
to Julien HENRY, jenkin...@googlegroups.com, SonarQube
The master/slave build is indeed missing the ceTaskId key:

<hudson.plugins.sonar.action.SonarAnalysisAction plugin="sonar@2.6">
<installationName>[my SonarQube env]</installationName>
<url>https://[sonarqube
url]/dashboard/index/org.sonarsource.clirr:sonar-clirr-plugin</url>
<isNew>true</isNew>
<isSkipped>false</isSkipped>
</hudson.plugins.sonar.action.SonarAnalysisAction>

Regards,

Jan

Idan Adar

unread,
Mar 22, 2017, 4:35:16 AM3/22/17
to SonarQube, julien...@sonarsource.com, jenkin...@googlegroups.com, jan....@thanksys.com
Question: what should  withSonarQubeEnv("SonarGate") use? should the text "sonargate" change to the label of the slave machine or is it a reference to a value in the Jenkins settings?
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/z_K_wz_8Vw8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

johan...@gmail.com

unread,
Mar 22, 2017, 4:39:39 AM3/22/17
to SonarQube, julien...@sonarsource.com, jenkin...@googlegroups.com, jan....@thanksys.com
withSonarQubeEnv() take the name of your sonarqube instance configured in the jenkins settings.

Jan Fabry

unread,
Mar 22, 2017, 4:43:12 AM3/22/17
to Idan Adar, SonarQube, Julien HENRY, jenkin...@googlegroups.com
Hello Idan,

That should be the name of one of the SonarQube servers you defined in
the Jenkins settings. So based on the images of your SO question [
https://stackoverflow.com/questions/42909439/using-waitforqualitygate-in-a-jenkins-declarative-pipeline
], it should be "SonarQube", the one in the final image.

One thing that this block does is set some environment variables, with
the hostname and authentication token you specified in the settings.
These environment variables can be used in your script, or are picked
up automatically by the scanner (but it's not always clear to me which
ones actually do that, and since which version).

Regards,

Jan

Julien HENRY

unread,
Mar 22, 2017, 4:57:01 AM3/22/17
to Jan Fabry, Idan Adar, SonarQube, jenkin...@googlegroups.com

2017-03-22 9:42 GMT+01:00 Jan Fabry <jan....@thanksys.com>:
(but it's not always clear to me which
ones actually do that, and since which version)

  - SQ Scanner 2.8+
  - SQ Scanner for Maven 3.1+
  - SQ Scanner for Gradle 2.1+

It doesn't work currently with the Scanner for MSBuild.

Idan Adar

unread,
Mar 22, 2017, 5:23:36 AM3/22/17
to SonarQube, jan....@thanksys.com, id...@adar.me, jenkin...@googlegroups.com
To recap,
I've updated the stage to: 

stage ("SonarQube analysis") {

   steps
{
      script
{
         withSonarQubeEnv
('SonarQube') {
            sh
"../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"  
         
}

         
         
def qualitygate = waitForQualityGate()
         
if (qualitygate.status != "OK") {
            error
"Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
         
}
     
}
   
}
}

It might be that doing this in the same stage it not possible?
This fails with: 

java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.

Under SonarQube servers section in the Jenkins settings I have: 
Name: SonarQube
Server: http://****:9000/sonarqube

In the console log I do see:

INFO: ANALYSIS SUCCESSFUL, you can browse http://****:9000/sonarqube/dashboard/index/cert-mgmt-dashboard
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://****:9000/sonarqube/api/ce/task?id=AVr1S35oyohgD3UCfaIt

The second link has this: 

{"task":{"organization":"default-organization","id":"AVr1S35oyohgD3UCfaIt","type":"REPORT","componentId":"AVrnCD3cyohgD3UCfaG0","componentKey":"****","componentName":"****","componentQualifier":"TRK","analysisId":"AVr1S4EhtEGQbCizBv8A","status":"SUCCESS","submittedAt":"2017-03-22T11:14:09+0200","submitterLogin":"****","startedAt":"2017-03-22T11:14:10+0200","executedAt":"2017-03-22T11:14:11+0200","executionTimeMs":473,"logs":false,"hasScannerContext":true}}

What is missing, other than this being run on a slave (the build machine used by Jenkins is also the same machine used for the SonarQube server)?

Julien HENRY

unread,
Mar 22, 2017, 6:20:13 AM3/22/17
to jenkin...@googlegroups.com, SonarQube, Jan Fabry, Idan Adar
Guys,

I was finally able to reproduce. Here is the ticket for details:

We will release a bugfix quickly for this specific problem.
The issue with Gradle will deserve more thinking and a dedicated sprint. BTW there is a workaround (--info) so that's not a blocker issue.

Thanks again for your feedback and help to investigate the issue. I will probably ask you to test the bugfix version before releasing it.

++

Julien

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/7so6S2mAhzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/9fe415f6-4f2c-435f-b77c-8158082818e5%40googlegroups.com.

johan...@gmail.com

unread,
Mar 22, 2017, 7:57:31 AM3/22/17
to SonarQube, jenkin...@googlegroups.com
Hello,

Thanks, but this doesn't solve my issue=/
I have the slave / master issue, but i'm not using Gradle, i'm using sonar-scanner 2.8 and jenkins 2.32.2. See more detail about my issue here: http://stackoverflow.com/questions/42898529/waitforqualitygate-exit-with-error-on-jenkins-slave

As you'll see, it's not the same issue.

In any case, thanks for your help, it's very appreciated :)

Regards,


On Wednesday, February 22, 2017 at 11:02:24 PM UTC+8, Julien HENRY wrote:
Hi,

I would like to collect feedback before the upcoming release of the SonarQube Scanner for Jenkins.

The main new feature is that we introduced a new pipeline step that would put the pipeline in pause until SonarQube analysis is finished, and the step will then give access to the quality gate status. You can then implement any logic you want.

Example:
      stage("build & SonarQube analysis") {
          node {
              withSonarQubeEnv('My SonarQube Server') {
                 sh 'mvn clean package sonar:sonar'
              }    
          }
      }
      
      stage("Quality Gate"){
          timeout(time: 1, unit: 'HOURS') {
              def qg = waitForQualityGate()
              if (qg.status != 'OK') {
                  error "Pipeline aborted due to quality gate failure: ${qg.status}"
              }
          }
      }

Julien HENRY

unread,
Mar 22, 2017, 10:53:16 AM3/22/17
to jenkin...@googlegroups.com, SonarQube, Jan Fabry, Idan Adar
Here is a release candidate fixing the issue with master/slave behavior:

Could you please test it and confirm that it solves your problems?

Thanks

Julien

Idan Adar

unread,
Mar 22, 2017, 11:22:17 AM3/22/17
to SonarQube, jenkin...@googlegroups.com, jan....@thanksys.com, id...@adar.me
I can confirm that in my case the updated plug-in now works!
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

Jan Fabry

unread,
Mar 22, 2017, 11:33:58 AM3/22/17
to Idan Adar, SonarQube, jenkin...@googlegroups.com
Yes, it also works for me now.

Regards, and thanks for the quick diagnosis and fix!

Jan Fabry

johan...@gmail.com

unread,
Mar 22, 2017, 8:56:09 PM3/22/17
to SonarQube, jenkin...@googlegroups.com
Thanks, it's working for me too : )

Julien HENRY

unread,
Mar 23, 2017, 5:27:49 AM3/23/17
to jenkin...@googlegroups.com, SonarQube, Jan Fabry, Idan Adar
Thanks Idan, we'll release 2.6.1.

To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/6415f21e-3570-4440-b043-0192746d59fa%40googlegroups.com.

ankit...@gmail.com

unread,
Jun 21, 2017, 8:16:22 AM6/21/17
to SonarQube, jenkin...@googlegroups.com
Hi Julien,

I am also facing the same issue :
java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:125)

Although I have only a single Jenkins Master instance and there is no slave.

My pipeline looks like: 

stage('SonarQube-Analysis'){
            steps {
                withSonarQubeEnv('SonarCube_Dev'){
                    sh 'mvn sonar:sonar'
                }
            }
        }
        stage("SonarQube-Quality Gate") { 
            steps {
                timeout(time: 1, unit: 'MINUTES') { 
                    script{
                   def qg = waitForQualityGate() 
                   if (qg.status != 'OK') {
                     error "Pipeline aborted due to quality gate failure: ${qg.status}"
                   }
                    }
                }
            }
        }

I am using SonarQube Scanner for Jenkins version : 2.6.1
Jenkins : 2.61

amal_j...@trimble.com

unread,
Jul 19, 2017, 6:18:09 AM7/19/17
to SonarQube, jenkin...@googlegroups.com
Hi Henry,

Does this quality gate functionality work with Sonar scanner for MSbuild? If yes then where should we add the "waitForQualityGate" method. Should it be added as part of "SonarQube.Scanner.MSBuild.exe begin" or after "SonarQube.Scanner.MSBuild.exe end" statement? I could not find any mention for Sonar scanner for MSBuild along with waitForQualityGate. Any help is deeply appreciated.

Thanks
Amal

pradeep....@gmail.com

unread,
Sep 15, 2017, 1:21:24 AM9/15/17
to SonarQube
Hi,

This quality gate functionality is not working with Sonar scanner for MSBuild. Below is the error. There is an additional slash in the url.
java.lang.IllegalStateException: Unable to parse response from http://XXX:9000//api/ce/task?id=AV6D5DbyM7CuBmXBR6FP:

Any idea how to fix this url?

Thanks,
Pradeep
Reply all
Reply to author
Forward
0 new messages