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 <timothy.dow...@gmail.com>: > Hi Julien, > > 'steps' is part of declarative pipeline which is becoming the > recommendation from the Jenkins folks on how to write your Jenkinsfiles. > > https://jenkins.io/doc/book/pipeline/ > > Tim > > On Tue, Mar 21, 2017 at 4:29 AM, Julien HENRY < > julien.he...@sonarsource.com> 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 <i...@adar.me>: >> >>> 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-waitforqu >>> alitygate-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: >>>> 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 a topic in the >>> Google Groups "Jenkins Developers" group. >>> To unsubscribe from this topic, visit https://groups.google.com/d/to >>> pic/jenkinsci-dev/7so6S2mAhzg/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> jenkinsci-dev+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/jenkinsci-dev/20c139a7-1e33-48d0-a9ae-ca5512f28785%40goo >>> glegroups.com >>> <https://groups.google.com/d/msgid/jenkinsci-dev/20c139a7-1e33-48d0-a9ae-ca5512f28785%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> 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/to >> pic/jenkinsci-dev/7so6S2mAhzg/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> jenkinsci-dev+unsubscr...@googlegroups.com. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/jenkinsci-dev/CAD9wyxENJfUfUhgkNL9hCLXtgig8%2B% >> 2BBQfrcKqiwMsRFu_FXErQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxENJfUfUhgkNL9hCLXtgig8%2B%2BBQfrcKqiwMsRFu_FXErQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> 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-dev+unsubscr...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/jenkinsci-dev/CAJp9yiNOAFmHvEZ5i4jWzA1ciiuTKJQfR%3Da79-PnBt6h4M2aqA% > 40mail.gmail.com > <https://groups.google.com/d/msgid/jenkinsci-dev/CAJp9yiNOAFmHvEZ5i4jWzA1ciiuTKJQfR%3Da79-PnBt6h4M2aqA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > 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 jenkinsci-dev+unsubscr...@googlegroups.com. 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.