【问题标题】:How to specify correct report-task.txt file in SonarQube Jenkins plugin?如何在 SonarQube Jenkins 插件中指定正确的 report-task.txt 文件?
【发布时间】:2022-06-28 04:10:43
【问题描述】:

我正在 Jenkins 中对我的 Node.js 项目进行 SonarQube 分析。声纳分析使用结果创建 report-task.txt 文件。不幸的是,node_modules 文件夹中的一些模块还包含它们的 report-task.txt 文件,这会导致 Jenkins 出现警告:

WARN: Found multiple 'report-task.txt' in the workspace. Taking the first one.
/jenkins/workspace/.scannerwork/report-task.txt
/jenkins/workspace/node_modules/some_module/.scannerwork/report-task.txt
/jenkins/workspace/node_modules/some_other_module/.scannerwork/report-task.txt

在我的项目的声纳分析失败之前一切都很好:然后 Jenkins 作为声纳分析的结果从 node_modules 中的模块获取不同的 report-task.txt 文件:

WARN: Found multiple 'report-task.txt' in the workspace. Taking the first one.
/jenkins/workspace/node_modules/some_module/.scannerwork/report-task.txt          <- wrong file
/jenkins/workspace/node_modules/some_other_module/.scannerwork/report-task.txt

有没有办法指定 /jenkins/workspace/.scannerwork/report-task.txt 是唯一正确的结果文件,而 Jenkins 应该忽略所有其他文件?最好使用 Jenkins Pipelines

【问题讨论】:

    标签: jenkins jenkins-pipeline sonarqube jenkins-plugins sonarqube-scan


    【解决方案1】:

    这是我的管道中的一个 sn-p:

    sh 'cat .scannerwork/report-task.txt'
    // copy to a properties file so we can ingest as variables
    sh 'cp .scannerwork/report-task.txt .scannerwork/report-task.properties'
    def props = readProperties file: '.scannerwork/report-task.properties'
    def ceTaskUrl= props['ceTaskUrl']
    def sonarServerUrl=props['serverUrl']
    // wait for analysis to complete
    waitUntil {
        def response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, url: "${ceTaskUrl}", wrapAsMultipart: false
        println "Sent a request, got a $response response"
        def body = readJSON text: response.content
        body.each { key, value -> }
        ceTask = body.task.status
        echo "Status is "+ceTask
        if ("FAILED".equals(ceTask)){
        echo "failed = "+ceTask
        throw new Exception(failed+" Sonar process failed!")
        }
        return "SUCCESS".equals(ceTask)
        sleep 30
    } 

    【讨论】:

      猜你喜欢
      • 2014-02-18
      • 2017-04-30
      • 2016-10-17
      • 2021-04-29
      • 2016-02-21
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      相关资源
      最近更新 更多