【问题标题】:Sonarscanner MSBuild tool is not running in pipeline - JenkinsSonarscanner MSBuild 工具未在管道中运行 - Jenkins
【发布时间】:2020-02-21 19:14:58
【问题描述】:

我正在运行以下管道,其中包含 dotnetcore 2.2 的“构建 + Sonarscanner 分析”阶段

舞台设置如下

  1. 我已按照建议在全局配置中安装了该工具 声纳库文档

  1. 在环境中定义工具如下
// Tools
        MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
  1. 管道阶段
stage ('Build + SonarQube analysis') {
            agent {
                docker { 
                    image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                }
            }
            steps {
                dir ("app") {
                    withSonarQubeEnv('local') {
                        sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                        sh "dotnet build ${env.DotnetProjectName}"
                        sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll end"
                    }
                }
            }
        }

结果

我得到 SonarScanner.MSBuild.dll 不可执行,如下所示

验证

  1. dll存在且权限分配给Jenkins
  2. dll 是可执行的
  3. 在该路径中手动运行的 dll - 它运行

  1. 直接添加dll的路径,结果一样
stage ('Build + SonarQube analysis') {
            agent {
                docker { 
                    image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                }
            }
            steps {
                dir ("app") {
                    withSonarQubeEnv('local') {
                        sh "dotnet /var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                        sh "dotnet build ${env.DotnetProjectName}"
                        sh "dotnet var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll end"
                    }
                }
            }
        }

提前感谢您的帮助。

【问题讨论】:

    标签: asp.net jenkins msbuild sonarqube sonarqube-scan


    【解决方案1】:

    我能够解决这个问题,

    1.在 Jenkins 工具中为 dotnetcore 安装了 SonarScanner

    声纳扫描仪的路径将与以前相同

    默认路径

    /var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll

    2。在 Jenkinsfile 中初始化工具

    // Tools
    MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
    
    stage ('Build + SonarQube analysis')
          agent {
                 docker { 
                      image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                      args '-v ${MSBUILD_SQ_SCANNER_HOME}:/opt/sonarscanner'
                    }
                }
                steps {
                    dir ("app") {
                        withSonarQubeEnv('local') {
                            sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                            sh "dotnet build ${env.DotnetProjectName}"
                            sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll end"
                        }
                    }
                }
            }
    

    它是如何工作的?

    1. 我正在将 sonarscanner 安装到路径 /opt/sonarscanner/ 的官方 docker 映像中
    2. 在初始化期间将挂载的文件作为 docker 容器的参数,现在 dll 可用于 docker dotnet 命令

    【讨论】:

    • 嗨@armourshield,你能帮我了解如何在jenkins工具中安装SonarScanner for dotnetcore。有没有它的插件。我只找到了普通的 SonarScanner 插件