当前位置: 首页 > 知识库问答 >
问题:

SonarQube waitForQualityGate()返回401

罗祺
2023-03-14
    null

我在SonarQube UI中配置了一个webhook,其URL如下。

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

我有一个詹金斯管道文件如下。

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('\r\n', ' ')
                        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"
        }
    }
}
Checking status of SonarQube task 'AWKwODGjKw9CRrvU3S27' on server 'Local'

Error 401 on http://mysonarserver.com:9000/api/ce/task?id=AWKwODGjKw9CRrvU3S27
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
{
    "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": {}
}

所以我现在不知道该去哪里?

任何帮助都将不胜感激!

暂时还没有答案

 类似资料:
  • 问题内容: 例如我有一个功能: 我怎样才能返回AJAX后得到的? 问题答案: 因为请求是异步的,所以您无法返回ajax请求的结果(而同步ajax请求是一个 糟糕的 主意)。 最好的选择是将自己的回调传递给f1 然后,您将像这样致电:

  • 问题内容: 我在使用Ajax时遇到问题。 问题是,在获得ajax响应之前,它会返回cnt。因此它总是返回NULL。 有没有办法使正确的返回响应值? 谢谢! 问题答案: 由于AJAX请求是异步的,因此您的cnt变量将在请求返回并调用成功处理程序之前返回。 我建议重构您的代码以解决此问题。 一种方法是从AJAX请求的成功处理程序中调用调用了GetGrantAmazonItemCnt()的任何函数,此方

  • 我想在下面返回JSON。 {“名字”:“杰基”} 新来的春靴在这里。1天大。有没有合适的方法可以做到这一点?

  • 问题内容: 我创建了一个自定义错误类型来包装错误,以便更轻松地在Golang中进行调试。当有打印错误时它可以工作,但是现在引起了恐慌。 演示版 当我调用一个函数时,它不会返回错误,我仍然应该能够包装该错误。 预期的行为是,如果错误为nil,则应该简单地忽略它,不幸的是,它会做相反的事情。 我希望它能打印出来。而是即使错误为nil也会打印。 问题答案: 正在将err变量与nil进行比较,但实际上它是

  • 问题内容: 有人可以向我解释为什么返回类型 只是返回类型 我不明白为什么地图会映射到一个以上的值。TIA。 问题答案: 它返回具有 相同 名称的控件的所有参数值。 例如: 要么 任何选中/选择的值都将以以下形式出现: 对于表中的多个选择它也很有用: 与…结合

  • 问题内容: 我有一类这样的方法: 我如何在另一个类中调用此方法? 问题答案: 1. 如果要从中调用该方法的类位于同一包中,则创建该类的实例并调用该方法。 2. 使用 3. 最好有个赞等等。 例如:

  • 这三个函数的返回类型提示有什么不同吗? 他们都应该有< code>- 提问的动机是这个问题,这个很好的答案,以及我正在学习类型提示的事实。

  • 我使用类型TreeMap定义了一个集合 我想返回与包含给定字符串值的列表配对的字符串(TreeMap键)。例如,我有一个字符串“bob”存储在列表中的一对中,我想返回与“bob”所在的对列表相关联的Treemap的键(字符串)。我将如何执行此操作?