i'm tring to use SonarQube inside my Jenkinsfile
pipeline{
agent any
stages{
stage('build'){
steps{
// invoke command to build with maven
bat 'mvn clean install'
}
}
stage('SonarQube') {
environment {
scannerHome = tool 'SonarQubeScanner'
}
steps {
withSonarQubeEnv('SonarQube') {
bat '${scannerHome}/bin/sonar-scanner.bat'
}
}
}
}
}
this is my SonarQube server
and this is SonarScanner
what is wrong with withSonarQubeEnv
step:
withSonarQubeEnv('SonarQube') {
bat '${scannerHome}/bin/sonar-scanner.bat'
}
that I always got an error
'${scannerHome}' is not recognized as an internal or external command,
I see two problems:
SonarQubeScanner
tool (only checkbox is checked)Single quotes are not evaluated (treat as is). It means that:
def value = 'ABC'
println '${value}/bin/sonar-scanner.bat'
prints ${value}/bin/sonar-scanner.bat
. You have to use double quotes:
def value = 'ABC'
println "${value}/bin/sonar-scanner.bat"
prints ABC/bin/sonar-scanner.bat
.
The code should be equal to:
withSonarQubeEnv('SonarQube') {
bat "${scannerHome}/bin/sonar-scanner.bat"
}