Sonarscanner MSBuild工具未在管道中运行-Jenkins

时间:2019-10-25 12:20:57

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

我正在运行下面的管道,该管道的dotnetcore 2.2处于“构建+ Sonarscanner分析”阶段。

阶段设置如下

  1. 我已经按照以下建议在全局配置中安装了该工具 Sonarqube文档

enter image description here

  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如下图所示无法执行

enter image description here

验证

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

enter image description here

  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"
                    }
                }
            }
        }

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题,

1。在Jenkins Tools中安装了适用于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. 我将声纳扫描仪安装到路径/ opt / sonarscanner /
  2. 上的官方docker映像
  3. 将装入的文件作为初始化期间docker容器的参数,现在dll可用于docker dotnet命令