I am interested in analysising my Jenkins builds via SonarQube. Initially, I have used the following code
stage('SonarCloud') {
steps {
withSonarQubeEnv('SonarQube') {
sh 'mvn clean package sonar:sonar '
}
}
}
However, I have asked here about how can I specify the quality gate that server uses for my analysis. From the answer provided, I have modified my code to look like this
stage('SonarCloud') {
steps {
withSonarQubeEnv('SonarQube') {
script{
def projectName = "Some-Exp"
// Creating a fresh project and placing it on the server - Works fine
sh "curl -u ${env.SONAR_AUTH_TOKEN} '${env.SONAR_HOST_URL}/api/projects/create' -d 'name=${projectName}&project=${projectName}&branch=${env.BRANCH_NAME}'"
// Specifying Quality Gate that to be used when performing our analysis - Does not quite work
sh "curl -u ${env.SONAR_AUTH_TOKEN} '${env.SONAR_HOST_URL}/api/qualitygates/select' -d 'gateId=2&projectKey=${projectName}'"
// Analysing our project - Creates the entirely new project, much like the initial code did
sh "mvn sonar:sonar -Dsonar.host.url=${env.SONAR_HOST_URL}"
}
}
}
}
The code creates and places a project on SonarQube server, but the said project still has a default quality gate, and it contains no analysis (in fact, current code creates an identical output to the one created by sh 'mvn clean package sonar:sonar '
line that I have used initially). There are no errors or anything. The problem is that the code does not do what I would like it to do.
This post mentioned that I need to add my project to profile group, before analysing it (which makes a lot sense). Tried to add sh "curl -u ${env.SONAR_AUTH_TOKEN} '${env.SONAR_HOST_URL}/api/qualityprofiles/add_project'"
with some parameters but it didn't help that much.
I wonder what am I missing. I think the final line needs to be parametrised but I could not find anything that would make it work.