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

Sonarscanner MSBuild tool is not running in pipeline - Jenkins

我正在 运行 设置以下管道,它具有 dotnetcore 2.2 "Build + Sonarscanner Analysis" 阶段

舞台设置如下

  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 is not executable 如下所示

验证

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

  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.在 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 命令