J'expérimente l'utilisation de travaux Pipeline avec le plugin bêta Blue Ocean activé sur notre serveur Jenkins.
Nous avons une étape de construction de scanner sonarqube configurée dans l'un de nos travaux de freestyle, pour laquelle je veux maintenant ajouter une étape pour mon fichier Jenkins.
Je vois dans les documents sonar qu'il existe un moyen d'y parvenir ici
Nous utilisons Jenkins 2.32.3 et avons installé le scanner SonarQube 2.8.
J'ai essayé le bloc de configuration d'étape suggéré, où notre scanner est nommé 'SonarQube Scanner'
stage('SonarQube analysis') {
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'SonarQube Scanner 2.8';
withSonarQubeEnv('SonarQube Scanner') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
Mais je reçois une erreur de Jenkins:
WorkflowScript: 29: Not a valid stage section definition: "def scannerHome = tool 'SonarQube Scanner 2.8'". Some extra configuration is required. @ line 29, column 5.
Qu'est-ce que je rate?
Merci
P.S - J'ai définitivement installé le scanner sonar:
Mise à jour
J'obtiens la sortie suivante dans le journal de la console:
hudson.remoting.ProxyException: Java.lang.IllegalArgumentException: Failed to prepare withSonarQubeEnv step
at org.jenkinsci.plugins.workflow.cps.DSL.invokeDescribable(DSL.Java:315)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.Java:129)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.Java:108)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.Java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.Java:151)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.Java:21)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.Java:115)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.Java:149)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.Java:146)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.Java:123)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.Java:16)
at WorkflowScript.run(WorkflowScript:46)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.delegateAndExecute(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:163)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:385)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:179)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.catchRequiredContextForNode(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:177)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.executeSingleStage(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:384)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:97)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:284)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.toolsBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:283)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:95)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:237)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withCredentialsBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:236)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:94)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:316)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:315)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:93)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:215)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:214)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:91)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.Java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.Java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.Java:82)
at Sun.reflect.GeneratedMethodAccessor355.invoke(Unknown Source)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:483)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.Java:72)
at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.Java:46)
at com.cloudbees.groovy.cps.Next.step(Next.Java:74)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.Java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.Java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.Java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.Java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.Java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.Java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.Java:165)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.Java:328)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.Java:80)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.Java:240)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.Java:228)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.Java:64)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.Java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.Java:28)
at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:511)
at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: hudson.AbortException: SonarQube installation defined in this job (SonarQube Scanner) does not match any configured installation. Number of installations that can be configured: 1.
If you want to reassign a lot of jobs to a different SonarQube installation see http://docs.sonarqube.org/display/PLUG/Reassign+Jobs+to+Another+SonarQube+Instance
at org.jenkinsci.plugins.workflow.cps.CpsStepContext.replay(CpsStepContext.Java:492)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.Java:213)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeDescribable(DSL.Java:313)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.Java:129)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.Java:108)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.Java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.Java:151)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.Java:21)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.Java:115)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.Java:149)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.Java:146)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.Java:123)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.Java:16)
... 29 more
Caused by: hudson.remoting.ProxyException: hudson.AbortException: SonarQube installation defined in this job (SonarQube Scanner) does not match any configured installation. Number of installations that can be configured: 1.
If you want to reassign a lot of jobs to a different SonarQube installation see http://docs.sonarqube.org/display/PLUG/Reassign+Jobs+to+Another+SonarQube+Instance
at hudson.plugins.sonar.SonarInstallation.checkValid(SonarInstallation.Java:170)
at hudson.plugins.sonar.SonarBuildWrapper.setUp(SonarBuildWrapper.Java:81)
at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Execution.start(CoreWrapperStep.Java:80)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.Java:184)
... 42 more
Finished: FAILURE
Mise à jour 2:
Gérer Jenkins> Configurer le système
Vous mélangez Scripted Pipeline avec la syntaxe Declarative Pipeline.
Bien que l'extrait que vous avez publié à partir de la documentation SonarQube fonctionne, vous devrez l'adapter car vous utilisez Declarative (comme indiqué par l'erreur "Not a valid stage section definition").
Normalement, vous définiriez une section tools
dans votre pipeline, mais il semble que le plug-in SonarQube ne prend pas en charge la déclaration, ni ne s'ajoute lui-même à la PATH
.
Comme vous ne pouvez pas normalement définir des variables dans le pipeline déclaratif, le script
étape doit être utilisé pour appeler le tool
étape et stocker le chemin d'accès à l'outil installé. Par exemple:
pipeline {
agent any
stages {
stage('SonarQube analysis') {
steps {
script {
// requires SonarQube Scanner 2.8+
scannerHome = tool 'SonarQube Scanner 2.8'
}
withSonarQubeEnv('SonarQube Scanner') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
}
Le nom tool
"SonarQube Scanner 2.8" doit correspondre au champ "Nom" d'une installation SonarQube sur la page de configuration des outils globaux. Le nom utilisé dans l'étape withSonarQubeEnv
doit correspondre au champ "Nom" d'un serveur SonarQube défini sur la page Configurer le système.
Si le plugin SonarQube supportait Declarative et s'ajoutait à PATH
, le Pipeline pourrait être un peu plus simple:
pipeline {
agent any
stages {
stage('SonarQube analysis') {
tools {
sonarQube 'SonarQube Scanner 2.8'
}
steps {
withSonarQubeEnv('SonarQube Scanner') {
sh 'sonar-scanner'
}
}
}
}
}