I followed these instructions to download the SonarQube Scanner plugin for Jenkins. I've configured these jenkins global settings for the SonarQube scanner correctly. The SonarQube server is setup and functioning properly.
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline
But when the build runs, it produces this error: No tool named SonarQube Scanner 2.8 found.
I am using a Jenkins declarative pipeline script for pipeline build.
I am using Jenkins ver. 2.131. I am using "SonarQube Scanner for Jenkins" Plugin version 2.8.1. I believe the Jenkins server is a common linux flavor. I am NOT using any version of Maven, and don't require it to build my projects.
I figured the plugin installed the actual scanner files for me on Jenkins. Do I need to have some version of the scanner command files installed, beyond whatever the plugin provided me? Meaning, is there something other than the plugin that I need to install on by Jenkins server? I would hope the SonarQube plugin would give me everything I would need to run on Jenkins build.
Here's the relavent part of my script:
stages {
stage("SonarQube Analysis") {
agent any
steps {
script {
def scannerHome = tool 'SonarQube Scanner 2.8';
withSonarQubeEnv("foo") {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
Here is a screenshot of the global configuration:
I think you didn't add Scanner in Jenkins Global Tool Configuration. You can do it by doing the following steps:
click Manage Jenkins
choose Global Tool Configuration
scroll to SonarQube Scanner
add SonarQube Scanner 2.8
May be would be actual for maven's users
stage("SonarQube analysis") {
steps {
script {
def scannerHome = tool 'SonarQube Scanner';
withSonarQubeEnv('SonarQube Server') {
sh 'mvn clean package sonar:sonar'
}
}
}
}
Related
Having some maven projects. I want to change it to a scripted pipeline in jenkins
To automate the following example you can use the Jenkins API via the groovy script console or an groovy system script to create you jobs programmatically.
Example for scripted Pipeline:
node{
stage ('Build') {
git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
}
}
You need the Pipeline Maven Plugin: https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
I try to use Pipeline script and I arrive until last step.
The Pipeline script is the following code
node{
stage ('Build') {
git url: 'https://xxx#bitbucket.org/xxx/01-eureka.git'
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
}
}
I have already been configured the maven and Java.
I don't know the error of the last step , I update all code.
I don't exact ENV as your's, but first thing first, you should check the your Jenkins workspace folder Jenkins\workspace\docker-app, to see if the git clone works as expected
If the source code are there, manual run the maven command to see if Maven finds the pom.xml correctly
Does SonarQube scanner support BlueOcean pipeline plugin without maven and docker, if it does how does the script works in Jenkinsfile?
I'm new to Jenkins and BlueOcean and have tried all the basic possible aspects available.
If the SonarQube plugin did support Declarative:
pipeline {
agent any
stages {
stage('SonarQube analysis') {
tools {
sonarQube 'SonarQube Scanner 2.8'
}
steps {
withSonarQubeEnv('SonarQube Scanner') {
sh 'sonar-scanner'
}
}
}
}
}
We cannot say that the SonarQube scanner supports or does not support BlueOcean. BlueOcean is a presentation layer which displays data provided by stages (example: logs).
SonarQube scanner generates logs, so BlueOcean can displays it. I do not think that this type of relationship can be classified as a "support of".
EDIT:
You can execute an analysis in Declarative Pipeline by using the following code:
pipeline {
agent any
stages {
stage('Build') {
steps {
def scannerHome = tool 'SonarQubeScanner3'
withSonarQubeEnv('SonarQube') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
}
You have also add a SonarQube server in Manage Jenkins → Configure System → SonarQube servers:
and SonarQube scanner in Manage Jenkins → Global Tool Configuration → SonarQube Scanner:
The name of the:
server must be the same as used in the withSonarQubeEnv (in my example it is equal to "SonarQube")
scanner tool must be the same as used in the tool (in my example it is equal to "SonarQubeScanner3")
You also have to check checkbox Enable injection of SonarQube server configuration as build environment variables.
it is solved one just need to check the tool location in general tool configs and give the path adn call it in jenkins file.
stage('PDNS-UI-Sonar') {
environment {
SONAR_SCANNER_OPTS = "-Xmx2g"
}
steps {
sh "pwd"
sh "/opt/sonar-scanner/bin/sonar-scanner -Dproject.settings=sonar-project.properties"
}
}
enter image description here
I defined a Jenkins Declarative pipeline to CI/CD my project. I am using gradle as my build tool. However I don't want to use the Gradle Wrapper and check it int the VCS. So I planed on using the jenkins tools functionality as below so that I can update the version number if I need to in future. But it doesn't seem to work.
pipeline {
agent any
tools {
gradle "gradle-4.0"
}
stage("Compile") {
steps {
sh 'gradle project/build.gradle classes'
}
}
I get the error "script.sh: gradle: not found".
I tried to echo PATH and that doesn't contain the path of this autoinstalled gradle tool. Please help.
Looks like there is an issue on the gradle plugin for Jenkins on plugin version 1.26. Please see the link to the bug reported below.
https://issues.jenkins-ci.org/browse/JENKINS-42381
At the moment we try to add SonarQube analyzing to our jenkins job pipeline. But every time the build job failed with the message: "java.lang.NoSuchMethodError: **No such DSL method withSonarQubeEnv". We have reinstall all plugins and configurations. Nothing help.
So maybe someone of you can help us.
What we have done:
Do all steps of this tutorial from sonarqube: Analyzing with SonarQube Scanner for Jenkins
Install SonarQube Plugin 2.5
Add and configure SonarQube under Manage Jenkins > Configure System
Add SonarQube Scanner under Manage Jenkins > Global Tool Configuration
Add this code after the checkout of our project to the groovy file for the pipeline:
stage('SonarQube analysis')
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'SonarQube Scanner 2.8';
withSonarQubeEnv('SonarQube 5.6.4') {
sh "${scannerHome}/bin/sonar-scanner"
}
Current Versions of our tools
Our Jenkins has the version 2.2
Our SonarQube Server has the version 5.6.4
The SonarQube Server run fine. We can analyzing our code over a local scanner.
I was trying to test with sonarqube 2.5 plugin but keep getting a different serialization error but have tested the below code which works fine and is without "withSonarQubeEnv" just in case you are looking for alternative:
stage('SonarQube analysis')
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'SonarQube Scanner 2.8';
sh "${scannerHome}/bin/sonar-scanner"
PS: I'll try to test with sonarqube 2.5 plugin and let you know if I find something.