struggled with this for a full 5 hours. thougt i should share what worked for me.
make subdirectory name the same as the repo name and run mvn sonar commands from there
SonarQube uses a java library from Eclipse jgit for the git work and this checks if the sonar.projectBaseDir has .git folder and some other git files/folders inside among other things.
N.B when the jenkins Git SCM clones it puts the contents of the repo directly on the workspace no dir is created
Setup:
SonarQube 7.7
Jenkins Declarative Pipeline
sample code:
checkout([$class: 'GitSCM', branches: [[name: branchName]],
doGenerateSubmoduleConfigurations: false, extensions: [ [$class: 'RelativeTargetDirectory', relativeTargetDir: "${env.artifactId}"]],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'credts', url: 'http://server.com/'+"${env.artifactId}"+'.git']]])
withSonarQubeEnv('Sonar Dev') {
sh 'cd ' + "${env.artifactId}" + ' && mvn -U clean package sonar:sonar '
}