I'm trying to create a Jenkins multibranch pipeline where on every push to bitbucket, a SonarQube analysis is performed on that branch of the project. Jenkins correctly creates the new job for each branch and a new project is created in SonarQube with the branch name appended to the project name.
The issue I'm having is that when SonarQube creates the new project, the webhook to report the Quality Gate status is not set by default, so I have to manually go into each SonarQube project and set the Webhook url. This is an issue when my team makes many branches a day.
Is there a way to specify in my Jenksfile that I want the SonarQube project to have a webhook?
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('Sonarqube Server') {
script {
def sonarScanner = tool name: 'SonarQube Scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
sh "${sonarScanner}/bin/sonar-scanner " +
"-Dsonar.projectKey=ProjectName-${GIT_BRANCH} " +
"-Dsonar.projectName=ProjectName-${GIT_BRANCH} " +
"-Dsonar.projectVersion=0.0.0 " +
"-Dsonar.sources=**/src " +
"-Dsonar.java.binaries=**/build " +
"-Dsonar.exclusions=excluded_dirs/** " +
"-Dsonar.sourceEncoding=UTF-8"
}
}
timeout(time: 5, unit: 'MINUTES') {
script {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to a quality gate failure: ${qg.status}"
}
}
}
}
}
Currently, my Jenkins build times out after 5 minutes. When the webhook is set, it takes a few seconds to hear back. My webhook url is correct, I just want the Jenkinsfile to set it, not me manually.
EDIT: Unfortunately, I am not an admin in SonarQube, only my projects