Error 401

Hi Sonar Team,
I am trying to run sonar-scanner and access quality gate results and am kind of stuck after trying various options suggested on forums. This is my first time trying to post, so please let me know if I am missing any details. I do see the json payload in sonarqube server webhooks console but it is in failed status (red cross-mark). Ours is a shared CBJ and SonarQube server with limited access for me on both of those. Any help/guidance is really appreciated. Thank you so much.

SonarQube Configuration

Project_Name > Administration > Webhooks
Name: Webhook_Name
URL: https://<CloudBeesJenkins_Server_FQDN>/dev-master/sonarqube-webhook/

CBJ Configuration

CredentialsID: ‘SonarQubeToken’: Value: <webhook_secret_text> Scope: Global credentials (unrestricted)

Jenkins Job - Pipeline Script

/* this stage succeeds */
stage(‘SonarQube Analysis’) {
def scannerHome = tool ‘Sonar-Prod’;
withSonarQubeEnv(‘Sonar-Prod’) {
sh “”"${scannerHome}/bin/sonar-scanner -X

/* fails at waitForQualityGate */
stage(“Quality Gate Status Check”) {
timeout(time: 1, unit: ‘HOURS’)// Just in case something goes wrong, pipeline will be killed after a timeout
// had previously tried using waitForQualityGate() and waitForQualityGate(webhookSecretId: ‘<webhook_secret_text>’ with same result
def qg = waitForQualityGate(webhookSecretId: ‘<webhook_secret_text>’, credentialsId: ‘<sonar_project_secret_text>’) // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != ‘OK’) {
error “Pipeline aborted due to quality gate failure: ${qg.status}”

Logs from Jenkins Server - Job Running
Sonarscanner and qualitygate

SonarQube Scanner
Java 1.8.0_242 Oracle Corporation (64-bit)
Linux 2.6.32-754.27.1.el6.x86_64 amd64
SonarQube server 7.9.1 - Community
[CloudBees Jenkins Enterprise]

09:40:13.671 DEBUG: Upload report
09:40:13.931 DEBUG: POST 200 https://<sonarqube_server_fqdn>/api/ce/submit?projectKey=ProjKey | time=256ms
09:40:13.935 INFO: Analysis report uploaded in 264ms
09:40:13.938 INFO: ANALYSIS SUCCESSFUL, you can browse https://<sonarqube_server_fqdn>/dashboard?id=ProjKey
09:40:13.938 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
09:40:13.938 INFO: More about the report processing at https://<sonarqube_server_fqdn>/api/ce/task?id=AXDt34Wae-uSoUyAgrS-

[Pipeline] waitForQualityGate
Checking status of SonarQube task ‘AXDt34Wae-uSoUyAgrS-’ on server ‘Sonar-Prod’ Error 401 on https://<sonarqube_server_fqdn>/api/ce/task?id=AXDt34Wae-uSoUyAgrS-

found a solution. had to define credentials in jenkins, scope global and use it waitForQualityGate(credentialsId: ‘<value_of_credentials_id>’)

1 Like