SonarQube waitForQualityGate() returning 401











up vote
0
down vote

favorite












I have a SonarQube server and a Jenkins server. The Jenkins server has the following plugins installed.




  • Quality Gates Plugin

  • Sonar Quality Gates Plugin

  • SonarQubeScanner


I have configured a webhook in the SonarQube UI with the following URL.



http://myjenkins.com:8083/sonarqube-webhook/



I have a Jenkins Pipeline file as below.



pipeline {
/*
* Run everything on an existing agent configured with a label 'windows'.
* TODO : Once we have enough agents, distribute to get fastest feedback!
*/
agent any
/*
agent {
node {
label 'windows'
}
}
*/
/*
* We are getting a lot of values from BitBucket notifier plugin.
*/
parameters {
string(defaultValue: '', description: '', name: 'PULL_REQUEST_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_VERSION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_SSH_CLONE_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ID')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TITLE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ACTION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_EMAIL_ADDRESS')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_STATE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_APPROVED_COUNT')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_PROJECT_KEY')
}

/* Add timestamps to the console log. Discard old builds.
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '20'))
}
*/
/* Stages can be parallel or sequential */
stages {
stage('Source-Code-Management') {
steps {
git(url: 'ssh://mybitbucketserver.com:7999/dev/sitecore.git', branch: '${PULL_REQUEST_FROM_BRANCH}', credentialsId: 'root')
powershell "git merge origin/${PULL_REQUEST_TO_BRANCH}"
}
}
stage('Build and Analyze') {
steps {
script {
// Todo we should be using environment variables or properties for sonar scanner and not have hardcoded values
bat ""${tool 'nuget-4.3.0'}" restore src/Nemlig.sln -NoCache"
withSonarQubeEnv('Local') {
bat ""${tool 'SonarScanner.MSBuild.exe'}" begin /d:sonar.login=mytoken /k:TEST /n:Website /v: /d:sonar.host.url=${SONAR_URL} /d:sonar.cs.nunit.reportsPaths=${WORKSPACE}\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=${WORKSPACE}\OpenCoverResult.xml"
bat ""${tool 'MSBuild-v15'}" src/Nemlig.sln /p:Configuration=debug"
// Note that this shell can retrieve value with CRLF and NUNIT will puke. Must replace with spaces...
def dlls = powershell(returnStdout: true, script: '(ls -Recurse src\*\bin\*.Test.dll | % FullName)')
dlls = dlls.replaceAll('rn', ' ')
mycmd = "OpenCover.Console.exe -register:path64 -target:"nunit3-console.exe" -returntargetcode -targetargs:"$dlls --result=NUnitResult.xml" -output:OpenCoverResult.xml"
powershell (returnStatus: true, script: "$mycmd")
bat ""${tool 'SonarScanner.MSBuild.exe'}" end /d:sonar.login=mytoken"
}
}
}
}
stage('SonarQube Quality Gate') {
steps {
script {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage('Deploy Team Environment') {
parallel {
stage('Deploy Site') {
steps {
powershell 'Write-Output "Here we could do a deploy of the site"'
}
}
stage('Deploy Backend') {
steps {
powershell 'Write-Output "Here we could do a deploy of the backend and maybe database changes?"'
}
}
}
}
stage('Smoke') {
parallel {
stage('Chrome') {
steps {
powershell 'Write-Output "Execute Smoke on Chrome"'
}
}
stage('Firefox') {
steps {
powershell 'Write-Output "Execute Smoke on Firefox"'
}
}
stage('Safari') {
steps {
powershell 'Write-Output "Execute Smoke on Safari"'
}
}
}
}
stage('integrate') {
steps {
powershell 'Write-Output "Push merge if all is success!"'
}
}
stage('Store Binary') {
steps {
powershell 'Write-Output "Put the tested binary in Artifactory. Maybe tag it with SHA and Build Number?"'
}
}
}
post {
// Add the publish merge steps...
// Add the notifiy Jira steps
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket()
}
nunit testResultsPattern: "NUnitResult.xml"
}
}
}


I execute the pipeline and the analysis is correctly processed and uploaded to the SonarQube server. However the waitForQualityGate always returns a 401.



Checking status of SonarQube task 'AWKwODGjKw9CRrvU3S27' on server 'Local'

Error 401 on http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27


I can see from the logs that the taskID that is generated during the analysis is the same.



ANALYSIS SUCCESSFUL, you can browse http://10.100.1.189:9000/dashboard/index/TEST
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27
INFO: Task total time: 3:00.752 s


I spun up a local RequestBin server setup a new webhook for that and saw that it did receive the data from SonarQube.



{
"serverUrl": "http://localhost:9000", "taskId": "AWKwODGjKw9CRrvU3S27", "status": "SUCCESS", "analysedAt":
"2018-04-11T07:41:40+0000", "changedAt": "2018-04-11T07:41:40+0000", "project":
{ "key": "TEST", "name": "Website", "url": "http://localhost:9000/dashboard?id=TEST" }, "branch":
{ "name": "master", "type": "LONG", "isMain": true, "url": "http://localhost:9000/dashboard?id=TEST" },
"qualityGate": {
"name": "Website", "status": "OK", "conditions": [{
"metric": "new_reliability_rating", "operator":
"GREATER_THAN", "value": "3", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "3"
}, {
"metric": "new_duplicated_lines_density", "operator":
"GREATER_THAN", "status": "NO_VALUE", "onLeakPeriod": true,
"errorThreshold": "3"
}, {
"metric": "new_security_rating", "operator": "GREATER_THAN",
"value": "4", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "4"
}, {
"metric": "blocker_violations", "operator": "GREATER_THAN",
"value": "-2", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "35"
}, {
"metric": "new_maintainability_rating", "operator":
"GREATER_THAN", "value": "1", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "1"
}]
}, "properties": {}
}


So I have no idea where to go now?



Any help would be appreciated!










share|improve this question
























  • Please check this, stackoverflow.com/questions/43588403/…
    – aBilal17
    Apr 11 at 7:43










  • @abilal17 - I already checked that and could not see a resolution.
    – tdh
    Apr 11 at 9:20















up vote
0
down vote

favorite












I have a SonarQube server and a Jenkins server. The Jenkins server has the following plugins installed.




  • Quality Gates Plugin

  • Sonar Quality Gates Plugin

  • SonarQubeScanner


I have configured a webhook in the SonarQube UI with the following URL.



http://myjenkins.com:8083/sonarqube-webhook/



I have a Jenkins Pipeline file as below.



pipeline {
/*
* Run everything on an existing agent configured with a label 'windows'.
* TODO : Once we have enough agents, distribute to get fastest feedback!
*/
agent any
/*
agent {
node {
label 'windows'
}
}
*/
/*
* We are getting a lot of values from BitBucket notifier plugin.
*/
parameters {
string(defaultValue: '', description: '', name: 'PULL_REQUEST_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_VERSION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_SSH_CLONE_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ID')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TITLE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ACTION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_EMAIL_ADDRESS')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_STATE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_APPROVED_COUNT')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_PROJECT_KEY')
}

/* Add timestamps to the console log. Discard old builds.
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '20'))
}
*/
/* Stages can be parallel or sequential */
stages {
stage('Source-Code-Management') {
steps {
git(url: 'ssh://mybitbucketserver.com:7999/dev/sitecore.git', branch: '${PULL_REQUEST_FROM_BRANCH}', credentialsId: 'root')
powershell "git merge origin/${PULL_REQUEST_TO_BRANCH}"
}
}
stage('Build and Analyze') {
steps {
script {
// Todo we should be using environment variables or properties for sonar scanner and not have hardcoded values
bat ""${tool 'nuget-4.3.0'}" restore src/Nemlig.sln -NoCache"
withSonarQubeEnv('Local') {
bat ""${tool 'SonarScanner.MSBuild.exe'}" begin /d:sonar.login=mytoken /k:TEST /n:Website /v: /d:sonar.host.url=${SONAR_URL} /d:sonar.cs.nunit.reportsPaths=${WORKSPACE}\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=${WORKSPACE}\OpenCoverResult.xml"
bat ""${tool 'MSBuild-v15'}" src/Nemlig.sln /p:Configuration=debug"
// Note that this shell can retrieve value with CRLF and NUNIT will puke. Must replace with spaces...
def dlls = powershell(returnStdout: true, script: '(ls -Recurse src\*\bin\*.Test.dll | % FullName)')
dlls = dlls.replaceAll('rn', ' ')
mycmd = "OpenCover.Console.exe -register:path64 -target:"nunit3-console.exe" -returntargetcode -targetargs:"$dlls --result=NUnitResult.xml" -output:OpenCoverResult.xml"
powershell (returnStatus: true, script: "$mycmd")
bat ""${tool 'SonarScanner.MSBuild.exe'}" end /d:sonar.login=mytoken"
}
}
}
}
stage('SonarQube Quality Gate') {
steps {
script {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage('Deploy Team Environment') {
parallel {
stage('Deploy Site') {
steps {
powershell 'Write-Output "Here we could do a deploy of the site"'
}
}
stage('Deploy Backend') {
steps {
powershell 'Write-Output "Here we could do a deploy of the backend and maybe database changes?"'
}
}
}
}
stage('Smoke') {
parallel {
stage('Chrome') {
steps {
powershell 'Write-Output "Execute Smoke on Chrome"'
}
}
stage('Firefox') {
steps {
powershell 'Write-Output "Execute Smoke on Firefox"'
}
}
stage('Safari') {
steps {
powershell 'Write-Output "Execute Smoke on Safari"'
}
}
}
}
stage('integrate') {
steps {
powershell 'Write-Output "Push merge if all is success!"'
}
}
stage('Store Binary') {
steps {
powershell 'Write-Output "Put the tested binary in Artifactory. Maybe tag it with SHA and Build Number?"'
}
}
}
post {
// Add the publish merge steps...
// Add the notifiy Jira steps
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket()
}
nunit testResultsPattern: "NUnitResult.xml"
}
}
}


I execute the pipeline and the analysis is correctly processed and uploaded to the SonarQube server. However the waitForQualityGate always returns a 401.



Checking status of SonarQube task 'AWKwODGjKw9CRrvU3S27' on server 'Local'

Error 401 on http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27


I can see from the logs that the taskID that is generated during the analysis is the same.



ANALYSIS SUCCESSFUL, you can browse http://10.100.1.189:9000/dashboard/index/TEST
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27
INFO: Task total time: 3:00.752 s


I spun up a local RequestBin server setup a new webhook for that and saw that it did receive the data from SonarQube.



{
"serverUrl": "http://localhost:9000", "taskId": "AWKwODGjKw9CRrvU3S27", "status": "SUCCESS", "analysedAt":
"2018-04-11T07:41:40+0000", "changedAt": "2018-04-11T07:41:40+0000", "project":
{ "key": "TEST", "name": "Website", "url": "http://localhost:9000/dashboard?id=TEST" }, "branch":
{ "name": "master", "type": "LONG", "isMain": true, "url": "http://localhost:9000/dashboard?id=TEST" },
"qualityGate": {
"name": "Website", "status": "OK", "conditions": [{
"metric": "new_reliability_rating", "operator":
"GREATER_THAN", "value": "3", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "3"
}, {
"metric": "new_duplicated_lines_density", "operator":
"GREATER_THAN", "status": "NO_VALUE", "onLeakPeriod": true,
"errorThreshold": "3"
}, {
"metric": "new_security_rating", "operator": "GREATER_THAN",
"value": "4", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "4"
}, {
"metric": "blocker_violations", "operator": "GREATER_THAN",
"value": "-2", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "35"
}, {
"metric": "new_maintainability_rating", "operator":
"GREATER_THAN", "value": "1", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "1"
}]
}, "properties": {}
}


So I have no idea where to go now?



Any help would be appreciated!










share|improve this question
























  • Please check this, stackoverflow.com/questions/43588403/…
    – aBilal17
    Apr 11 at 7:43










  • @abilal17 - I already checked that and could not see a resolution.
    – tdh
    Apr 11 at 9:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a SonarQube server and a Jenkins server. The Jenkins server has the following plugins installed.




  • Quality Gates Plugin

  • Sonar Quality Gates Plugin

  • SonarQubeScanner


I have configured a webhook in the SonarQube UI with the following URL.



http://myjenkins.com:8083/sonarqube-webhook/



I have a Jenkins Pipeline file as below.



pipeline {
/*
* Run everything on an existing agent configured with a label 'windows'.
* TODO : Once we have enough agents, distribute to get fastest feedback!
*/
agent any
/*
agent {
node {
label 'windows'
}
}
*/
/*
* We are getting a lot of values from BitBucket notifier plugin.
*/
parameters {
string(defaultValue: '', description: '', name: 'PULL_REQUEST_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_VERSION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_SSH_CLONE_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ID')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TITLE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ACTION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_EMAIL_ADDRESS')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_STATE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_APPROVED_COUNT')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_PROJECT_KEY')
}

/* Add timestamps to the console log. Discard old builds.
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '20'))
}
*/
/* Stages can be parallel or sequential */
stages {
stage('Source-Code-Management') {
steps {
git(url: 'ssh://mybitbucketserver.com:7999/dev/sitecore.git', branch: '${PULL_REQUEST_FROM_BRANCH}', credentialsId: 'root')
powershell "git merge origin/${PULL_REQUEST_TO_BRANCH}"
}
}
stage('Build and Analyze') {
steps {
script {
// Todo we should be using environment variables or properties for sonar scanner and not have hardcoded values
bat ""${tool 'nuget-4.3.0'}" restore src/Nemlig.sln -NoCache"
withSonarQubeEnv('Local') {
bat ""${tool 'SonarScanner.MSBuild.exe'}" begin /d:sonar.login=mytoken /k:TEST /n:Website /v: /d:sonar.host.url=${SONAR_URL} /d:sonar.cs.nunit.reportsPaths=${WORKSPACE}\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=${WORKSPACE}\OpenCoverResult.xml"
bat ""${tool 'MSBuild-v15'}" src/Nemlig.sln /p:Configuration=debug"
// Note that this shell can retrieve value with CRLF and NUNIT will puke. Must replace with spaces...
def dlls = powershell(returnStdout: true, script: '(ls -Recurse src\*\bin\*.Test.dll | % FullName)')
dlls = dlls.replaceAll('rn', ' ')
mycmd = "OpenCover.Console.exe -register:path64 -target:"nunit3-console.exe" -returntargetcode -targetargs:"$dlls --result=NUnitResult.xml" -output:OpenCoverResult.xml"
powershell (returnStatus: true, script: "$mycmd")
bat ""${tool 'SonarScanner.MSBuild.exe'}" end /d:sonar.login=mytoken"
}
}
}
}
stage('SonarQube Quality Gate') {
steps {
script {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage('Deploy Team Environment') {
parallel {
stage('Deploy Site') {
steps {
powershell 'Write-Output "Here we could do a deploy of the site"'
}
}
stage('Deploy Backend') {
steps {
powershell 'Write-Output "Here we could do a deploy of the backend and maybe database changes?"'
}
}
}
}
stage('Smoke') {
parallel {
stage('Chrome') {
steps {
powershell 'Write-Output "Execute Smoke on Chrome"'
}
}
stage('Firefox') {
steps {
powershell 'Write-Output "Execute Smoke on Firefox"'
}
}
stage('Safari') {
steps {
powershell 'Write-Output "Execute Smoke on Safari"'
}
}
}
}
stage('integrate') {
steps {
powershell 'Write-Output "Push merge if all is success!"'
}
}
stage('Store Binary') {
steps {
powershell 'Write-Output "Put the tested binary in Artifactory. Maybe tag it with SHA and Build Number?"'
}
}
}
post {
// Add the publish merge steps...
// Add the notifiy Jira steps
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket()
}
nunit testResultsPattern: "NUnitResult.xml"
}
}
}


I execute the pipeline and the analysis is correctly processed and uploaded to the SonarQube server. However the waitForQualityGate always returns a 401.



Checking status of SonarQube task 'AWKwODGjKw9CRrvU3S27' on server 'Local'

Error 401 on http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27


I can see from the logs that the taskID that is generated during the analysis is the same.



ANALYSIS SUCCESSFUL, you can browse http://10.100.1.189:9000/dashboard/index/TEST
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27
INFO: Task total time: 3:00.752 s


I spun up a local RequestBin server setup a new webhook for that and saw that it did receive the data from SonarQube.



{
"serverUrl": "http://localhost:9000", "taskId": "AWKwODGjKw9CRrvU3S27", "status": "SUCCESS", "analysedAt":
"2018-04-11T07:41:40+0000", "changedAt": "2018-04-11T07:41:40+0000", "project":
{ "key": "TEST", "name": "Website", "url": "http://localhost:9000/dashboard?id=TEST" }, "branch":
{ "name": "master", "type": "LONG", "isMain": true, "url": "http://localhost:9000/dashboard?id=TEST" },
"qualityGate": {
"name": "Website", "status": "OK", "conditions": [{
"metric": "new_reliability_rating", "operator":
"GREATER_THAN", "value": "3", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "3"
}, {
"metric": "new_duplicated_lines_density", "operator":
"GREATER_THAN", "status": "NO_VALUE", "onLeakPeriod": true,
"errorThreshold": "3"
}, {
"metric": "new_security_rating", "operator": "GREATER_THAN",
"value": "4", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "4"
}, {
"metric": "blocker_violations", "operator": "GREATER_THAN",
"value": "-2", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "35"
}, {
"metric": "new_maintainability_rating", "operator":
"GREATER_THAN", "value": "1", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "1"
}]
}, "properties": {}
}


So I have no idea where to go now?



Any help would be appreciated!










share|improve this question















I have a SonarQube server and a Jenkins server. The Jenkins server has the following plugins installed.




  • Quality Gates Plugin

  • Sonar Quality Gates Plugin

  • SonarQubeScanner


I have configured a webhook in the SonarQube UI with the following URL.



http://myjenkins.com:8083/sonarqube-webhook/



I have a Jenkins Pipeline file as below.



pipeline {
/*
* Run everything on an existing agent configured with a label 'windows'.
* TODO : Once we have enough agents, distribute to get fastest feedback!
*/
agent any
/*
agent {
node {
label 'windows'
}
}
*/
/*
* We are getting a lot of values from BitBucket notifier plugin.
*/
parameters {
string(defaultValue: '', description: '', name: 'PULL_REQUEST_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_VERSION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_SSH_CLONE_URL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ID')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TITLE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_ACTION')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_SLUG')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_AUTHOR_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_EMAIL_ADDRESS')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_USER_DISPLAY_NAME')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_STATE')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_EMAIL')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_REVIEWERS_APPROVED_COUNT')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_FROM_BRANCH')
string(defaultValue: '', description: '', name: 'PULL_REQUEST_TO_REPO_PROJECT_KEY')
}

/* Add timestamps to the console log. Discard old builds.
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '20'))
}
*/
/* Stages can be parallel or sequential */
stages {
stage('Source-Code-Management') {
steps {
git(url: 'ssh://mybitbucketserver.com:7999/dev/sitecore.git', branch: '${PULL_REQUEST_FROM_BRANCH}', credentialsId: 'root')
powershell "git merge origin/${PULL_REQUEST_TO_BRANCH}"
}
}
stage('Build and Analyze') {
steps {
script {
// Todo we should be using environment variables or properties for sonar scanner and not have hardcoded values
bat ""${tool 'nuget-4.3.0'}" restore src/Nemlig.sln -NoCache"
withSonarQubeEnv('Local') {
bat ""${tool 'SonarScanner.MSBuild.exe'}" begin /d:sonar.login=mytoken /k:TEST /n:Website /v: /d:sonar.host.url=${SONAR_URL} /d:sonar.cs.nunit.reportsPaths=${WORKSPACE}\NUnitResult.xml /d:sonar.cs.opencover.reportsPaths=${WORKSPACE}\OpenCoverResult.xml"
bat ""${tool 'MSBuild-v15'}" src/Nemlig.sln /p:Configuration=debug"
// Note that this shell can retrieve value with CRLF and NUNIT will puke. Must replace with spaces...
def dlls = powershell(returnStdout: true, script: '(ls -Recurse src\*\bin\*.Test.dll | % FullName)')
dlls = dlls.replaceAll('rn', ' ')
mycmd = "OpenCover.Console.exe -register:path64 -target:"nunit3-console.exe" -returntargetcode -targetargs:"$dlls --result=NUnitResult.xml" -output:OpenCoverResult.xml"
powershell (returnStatus: true, script: "$mycmd")
bat ""${tool 'SonarScanner.MSBuild.exe'}" end /d:sonar.login=mytoken"
}
}
}
}
stage('SonarQube Quality Gate') {
steps {
script {
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage('Deploy Team Environment') {
parallel {
stage('Deploy Site') {
steps {
powershell 'Write-Output "Here we could do a deploy of the site"'
}
}
stage('Deploy Backend') {
steps {
powershell 'Write-Output "Here we could do a deploy of the backend and maybe database changes?"'
}
}
}
}
stage('Smoke') {
parallel {
stage('Chrome') {
steps {
powershell 'Write-Output "Execute Smoke on Chrome"'
}
}
stage('Firefox') {
steps {
powershell 'Write-Output "Execute Smoke on Firefox"'
}
}
stage('Safari') {
steps {
powershell 'Write-Output "Execute Smoke on Safari"'
}
}
}
}
stage('integrate') {
steps {
powershell 'Write-Output "Push merge if all is success!"'
}
}
stage('Store Binary') {
steps {
powershell 'Write-Output "Put the tested binary in Artifactory. Maybe tag it with SHA and Build Number?"'
}
}
}
post {
// Add the publish merge steps...
// Add the notifiy Jira steps
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket()
}
nunit testResultsPattern: "NUnitResult.xml"
}
}
}


I execute the pipeline and the analysis is correctly processed and uploaded to the SonarQube server. However the waitForQualityGate always returns a 401.



Checking status of SonarQube task 'AWKwODGjKw9CRrvU3S27' on server 'Local'

Error 401 on http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27


I can see from the logs that the taskID that is generated during the analysis is the same.



ANALYSIS SUCCESSFUL, you can browse http://10.100.1.189:9000/dashboard/index/TEST
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27
INFO: Task total time: 3:00.752 s


I spun up a local RequestBin server setup a new webhook for that and saw that it did receive the data from SonarQube.



{
"serverUrl": "http://localhost:9000", "taskId": "AWKwODGjKw9CRrvU3S27", "status": "SUCCESS", "analysedAt":
"2018-04-11T07:41:40+0000", "changedAt": "2018-04-11T07:41:40+0000", "project":
{ "key": "TEST", "name": "Website", "url": "http://localhost:9000/dashboard?id=TEST" }, "branch":
{ "name": "master", "type": "LONG", "isMain": true, "url": "http://localhost:9000/dashboard?id=TEST" },
"qualityGate": {
"name": "Website", "status": "OK", "conditions": [{
"metric": "new_reliability_rating", "operator":
"GREATER_THAN", "value": "3", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "3"
}, {
"metric": "new_duplicated_lines_density", "operator":
"GREATER_THAN", "status": "NO_VALUE", "onLeakPeriod": true,
"errorThreshold": "3"
}, {
"metric": "new_security_rating", "operator": "GREATER_THAN",
"value": "4", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "4"
}, {
"metric": "blocker_violations", "operator": "GREATER_THAN",
"value": "-2", "status": "OK", "onLeakPeriod": true,
"errorThreshold": "35"
}, {
"metric": "new_maintainability_rating", "operator":
"GREATER_THAN", "value": "1", "status": "OK", "onLeakPeriod":
true, "errorThreshold": "1"
}]
}, "properties": {}
}


So I have no idea where to go now?



Any help would be appreciated!







sonarqube jenkins-pipeline






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 11 at 7:52

























asked Apr 11 at 7:38









tdh

266




266












  • Please check this, stackoverflow.com/questions/43588403/…
    – aBilal17
    Apr 11 at 7:43










  • @abilal17 - I already checked that and could not see a resolution.
    – tdh
    Apr 11 at 9:20


















  • Please check this, stackoverflow.com/questions/43588403/…
    – aBilal17
    Apr 11 at 7:43










  • @abilal17 - I already checked that and could not see a resolution.
    – tdh
    Apr 11 at 9:20
















Please check this, stackoverflow.com/questions/43588403/…
– aBilal17
Apr 11 at 7:43




Please check this, stackoverflow.com/questions/43588403/…
– aBilal17
Apr 11 at 7:43












@abilal17 - I already checked that and could not see a resolution.
– tdh
Apr 11 at 9:20




@abilal17 - I already checked that and could not see a resolution.
– tdh
Apr 11 at 9:20












2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










The waitForQualityGate() step needs some credentials to fetch quality gate details from the SQ server. The credentials are expected to be set in Jenkins global configuration, for your 'Local' server.



But according to your pipeline snippet, I see that you are passing manually /d:sonar.login=mytoken to the scanner. This is not supported. Please set the token in the global server configuration.






share|improve this answer

















  • 1




    I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
    – tdh
    Apr 12 at 6:50




















up vote
0
down vote













OK I got it to work. I updated the Jenkins users token. Copied it and added it as an environment variable in Jenkins Global configuration. Then went through my pipeline script and used the environment variable in all calls to SonarQube.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49769197%2fsonarqube-waitforqualitygate-returning-401%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    The waitForQualityGate() step needs some credentials to fetch quality gate details from the SQ server. The credentials are expected to be set in Jenkins global configuration, for your 'Local' server.



    But according to your pipeline snippet, I see that you are passing manually /d:sonar.login=mytoken to the scanner. This is not supported. Please set the token in the global server configuration.






    share|improve this answer

















    • 1




      I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
      – tdh
      Apr 12 at 6:50

















    up vote
    3
    down vote



    accepted










    The waitForQualityGate() step needs some credentials to fetch quality gate details from the SQ server. The credentials are expected to be set in Jenkins global configuration, for your 'Local' server.



    But according to your pipeline snippet, I see that you are passing manually /d:sonar.login=mytoken to the scanner. This is not supported. Please set the token in the global server configuration.






    share|improve this answer

















    • 1




      I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
      – tdh
      Apr 12 at 6:50















    up vote
    3
    down vote



    accepted







    up vote
    3
    down vote



    accepted






    The waitForQualityGate() step needs some credentials to fetch quality gate details from the SQ server. The credentials are expected to be set in Jenkins global configuration, for your 'Local' server.



    But according to your pipeline snippet, I see that you are passing manually /d:sonar.login=mytoken to the scanner. This is not supported. Please set the token in the global server configuration.






    share|improve this answer












    The waitForQualityGate() step needs some credentials to fetch quality gate details from the SQ server. The credentials are expected to be set in Jenkins global configuration, for your 'Local' server.



    But according to your pipeline snippet, I see that you are passing manually /d:sonar.login=mytoken to the scanner. This is not supported. Please set the token in the global server configuration.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 11 at 11:52









    Julien H. - SonarSource Team

    3,8371114




    3,8371114








    • 1




      I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
      – tdh
      Apr 12 at 6:50
















    • 1




      I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
      – tdh
      Apr 12 at 6:50










    1




    1




    I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
    – tdh
    Apr 12 at 6:50






    I have a user called Jenkins in the SonarQube Server. I generated a token for this user. I added this token to the global SonarServer configuration under Manage Jenkins->Configure system->SonarQube Servers. I get the same result.
    – tdh
    Apr 12 at 6:50














    up vote
    0
    down vote













    OK I got it to work. I updated the Jenkins users token. Copied it and added it as an environment variable in Jenkins Global configuration. Then went through my pipeline script and used the environment variable in all calls to SonarQube.






    share|improve this answer

























      up vote
      0
      down vote













      OK I got it to work. I updated the Jenkins users token. Copied it and added it as an environment variable in Jenkins Global configuration. Then went through my pipeline script and used the environment variable in all calls to SonarQube.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        OK I got it to work. I updated the Jenkins users token. Copied it and added it as an environment variable in Jenkins Global configuration. Then went through my pipeline script and used the environment variable in all calls to SonarQube.






        share|improve this answer












        OK I got it to work. I updated the Jenkins users token. Copied it and added it as an environment variable in Jenkins Global configuration. Then went through my pipeline script and used the environment variable in all calls to SonarQube.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 12 at 7:43









        tdh

        266




        266






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49769197%2fsonarqube-waitforqualitygate-returning-401%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga