[RFF] SonarQube Scanner for Jenkins 2.6

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Arnaud Héritier
Myself I like it !!

On Wed, Feb 22, 2017 at 4:02 PM, Julien HENRY <[hidden email]> 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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFNCU-_siwgRjAiN%3DzX4oZJ0yDEBvKT5jqfYt-RP%3DYu198m2Tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Jesse Glick-4
In reply to this post by Julien HENRY-2
On Wed, Feb 22, 2017 at 10:02 AM, Julien HENRY
<[hidden email]> wrote:
> I would like to collect feedback before the upcoming release of the
> SonarQube Scanner for Jenkins.

Left some code review comments for you.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr3f8v3gy39ovCTFrpMMVJDknonsGiL3JFEpPva2RvT3YQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Tim Downey
In reply to this post by Julien HENRY-2
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...


On Wednesday, February 22, 2017 at 10:02:30 AM UTC-5, 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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/19027f4d-2246-4c35-b71c-9a9ef20abee2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Jesse Glick-4
On Wed, Feb 22, 2017 at 12:13 PM, Tim Downey <[hidden email]> wrote:

> 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}"
>       }
>     }
>   }
> }

BTW if the step had an option to return void but mark the build
`UNSTABLE` where appropriate, you could write more simply

steps {
  withSonarQubeEnv(…) {
    sh '…'
    waitForQualityGate markBuildUnstable: true
  }
}

which the round-trip GUI editor could handle because there would be no
need for a `script` block.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr16SRZeMdUp-u9U%3DAXRNCzcUpGBPfNPROQh9KmhcQyYYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
In reply to this post by Tim Downey
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


Le mercredi 22 février 2017 18:13:09 UTC+1, Tim Downey a écrit :
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...


On Wednesday, February 22, 2017 at 10:02:30 AM UTC-5, 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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/f9154b14-2ca3-4779-a642-29c51c46a794%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

georg.henzler
In reply to this post by Julien HENRY-2
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

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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/cd1b94a5-4fe1-47ac-b4ee-54db83ef8499%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Laurent Tourreau
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/4b4ae9ff-a20f-4715-8f69-e29e9682d777%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Laurent Tourreau
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/fcc036ec-c137-4456-a353-787ff917877f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
In reply to this post by georg.henzler
Hi Georg,

Le mardi 28 février 2017 14:02:33 UTC+1, [hidden email] a écrit :
Hi Julien, 

this feature is nice but it has been easily possible to achieve the same with <a href="https://github.com/SonarQubeCommunity/sonar-build-breaker" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FSonarQubeCommunity%2Fsonar-build-breaker\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHuJo_EVQtDQl-aPgIIDD005Q7oUw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FSonarQubeCommunity%2Fsonar-build-breaker\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHuJo_EVQtDQl-aPgIIDD005Q7oUw&#39;;return true;">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.
 
(or <a href="https://github.com/AmadeusITGroup/sonar-stash" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FAmadeusITGroup%2Fsonar-stash\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFFhB1zrYR5IEePo7UhIxstNRqKCw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FAmadeusITGroup%2Fsonar-stash\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFFhB1zrYR5IEePo7UhIxstNRqKCw&#39;;return true;">https://github.com/AmadeusITGroup/sonar-stash that we use ATM). 

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 <a href="https://www.google.com/url?q=https%3A%2F%2Fjira.sonarsource.com%2Fbrowse%2FSONAR-6763&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGnwGKfz6SPcgK_wbQgShbuIyiYxw" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjira.sonarsource.com%2Fbrowse%2FSONAR-6763\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGnwGKfz6SPcgK_wbQgShbuIyiYxw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjira.sonarsource.com%2Fbrowse%2FSONAR-6763\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGnwGKfz6SPcgK_wbQgShbuIyiYxw&#39;;return true;">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.
 

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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/055101bf-7873-4656-8bb2-8ac8a928c5b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

arvidhuss
In reply to this post by Julien HENRY-2
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

Den fredag 24 februari 2017 kl. 16:42:29 UTC skrev Julien HENRY:
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


Le mercredi 22 février 2017 18:13:09 UTC+1, Tim Downey a écrit :
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...


On Wednesday, February 22, 2017 at 10:02:30 AM UTC-5, 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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/d7c7c00c-d534-4587-8aaa-9712cc79935d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
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

2017-03-14 10:11 GMT+01:00 Arvid Huss <[hidden email]>:
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


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEuQLNm2jcet89bymD%3DVQYzzfP5Hv-5yqWFPF8Qky7xig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
In reply to this post by Julien HENRY-2
Hi Jan,

Le mercredi 15 mars 2017 11:11:30 UTC+1, [hidden email] 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
 

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

On Friday, 24 February 2017 17:42:24 UTC+1, Julien HENRY wrote:
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


Le mercredi 22 février 2017 18:13:09 UTC+1, Tim Downey a écrit :
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...


On Wednesday, February 22, 2017 at 10:02:30 AM UTC-5, 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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/ecaea6e9-b898-45c8-b49f-77243ea21b2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Idan Adar
In reply to this post by Julien HENRY-2
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...
https://stackoverflow.com/questions/42909439/using-waitforqualitygate-in-a-jenkins-declarative-pipeline


On Wednesday, February 22, 2017 at 5:02:24 PM UTC+2, 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:
<a href="https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frepox.sonarsource.com%2Fsonarsource-public-builds%2Forg%2Fjenkins-ci%2Fplugins%2Fsonar%2F2.6-build1166%2Fsonar-2.6-build1166.hpi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEH2o2suYafd_8pTsjZVoVzxqUbqA&#39;;return true;">https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6-build1166/sonar-2.6-build1166.hpi

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 "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
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}"
              } 
           }
  }


2017-03-20 23:46 GMT+01:00 Idan Adar <[hidden email]>:
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...


On Wednesday, February 22, 2017 at 5:02:24 PM UTC+2, 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 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 [hidden email].
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 the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Tim Downey
Hi Julien,

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


Tim

On Tue, Mar 21, 2017 at 4:29 AM, Julien HENRY <[hidden email]> wrote:
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}"
              } 
           }
  }


2017-03-20 23:46 GMT+01:00 Idan Adar <[hidden email]>:
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...


On Wednesday, February 22, 2017 at 5:02:24 PM UTC+2, 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 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 [hidden email].
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 [hidden email].
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 the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAJp9yiNOAFmHvEZ5i4jWzA1ciiuTKJQfR%3Da79-PnBt6h4M2aqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
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  {
                        def qg = waitForQualityGate()
                        if (qg.status != 'OK') {
                            error "Pipeline aborted due to quality gate failure: ${qg.status}"
                        }
                    }
                }
            }
        }
    }
}


2017-03-21 12:23 GMT+01:00 Tim Downey <[hidden email]>:
Hi Julien,

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


Tim

On Tue, Mar 21, 2017 at 4:29 AM, Julien HENRY <[hidden email]> wrote:
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}"
              } 
           }
  }


2017-03-20 23:46 GMT+01:00 Idan Adar <[hidden email]>:
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...


On Wednesday, February 22, 2017 at 5:02:24 PM UTC+2, 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 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 [hidden email].
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 [hidden email].
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAJp9yiNOAFmHvEZ5i4jWzA1ciiuTKJQfR%3Da79-PnBt6h4M2aqA%40mail.gmail.com.

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEf%2BR_tbPQwfCUYnrw8DW5ftePsfsP%2B5QLzEXSW4z4nuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Jesse Glick-4
On Tue, Mar 21, 2017 at 8:40 AM, Julien HENRY
<[hidden email]> wrote:
> script {

Should not be necessary AFAIK—you can use block-scoped steps like
`withSonarQubeEnv`.

> withEnv(["JAVA_HOME=${ tool '8u121' }", "PATH+MAVEN=${tool '3.3.9'}/bin:${env.JAVA_HOME}/bin"]) {

`tools` section

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

This part is not Declarative-friendly. You could add an option to
`waitForQualityGate` to set the build result to `UNSTABLE`.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0g8RbAwDq13wa6Qm5nu5VagvVKENN2eVD5V%3DHF6ONHFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2

2017-03-21 14:42 GMT+01:00 Jesse Glick <[hidden email]>:
On Tue, Mar 21, 2017 at 8:40 AM, Julien HENRY
<[hidden email]> wrote:
> script {

Should not be necessary AFAIK—you can use block-scoped steps like
`withSonarQubeEnv`.

> withEnv(["JAVA_HOME=${ tool '8u121' }", "PATH+MAVEN=${tool '3.3.9'}/bin:${env.JAVA_HOME}/bin"]) {

`tools` section

Indeed, it works fine without script block. 

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

This part is not Declarative-friendly. You could add an option to
`waitForQualityGate` to set the build result to `UNSTABLE`.

Here is a ticket: https://jira.sonarsource.com/browse/SONARJNKNS-280

Still that doesn't explain why the "communication" between the withSonarQubeEnv and the waitForQualityGate steps is not working for some people.

Jesse, withSonarQubeEnv is a SimpleBuildWrapper. We attach to it a Disposer that collect some properties, and attach them to the build using an InvisibleAction. Then later the waitForQualityGate step try to read it back to get the values. For some people it seems to fail somewhere, in a mater/slave configuration. I was not able to reproduce but are you aware of any problem with this approach?

Thanks

Julien

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEaRoFuvffGq8bx%2Bn8CjirFwLMao1pEPSUq5aDKV0Zbxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [RFF] SonarQube Scanner for Jenkins 2.6

Julien HENRY-2
In reply to this post by Julien HENRY-2
Hi Jan,

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

2017-03-21 19:32 GMT+01:00 Jan Fabry <[hidden email]>:
Let me know if  you want any other tests.

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

++

Julien

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxH88hozgKwCix_o0hiuOYMA%2B5U1K73JOF-THifQGjzwGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
12