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

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

仉昱
2023-03-14

我正在运行下面的管道,它为DotNetCore2.2运行“构建+声呐扫描程序分析”阶段

舞台设置如下

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

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

  1. 该dll存在并且权限已分配给Jenkins
  2. 该dll是可执行的
  3. 在该路径中手动运行时的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个答案

越朗
2023-03-14

我解决了这个问题,

1.在Jenkins Tools中为dotnetcore安装了SonarScanner

sonarscanner的路径将与以前相同

// 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/
  2. 的官方docker映像
  3. 在初始化期间,装入的文件作为docker容器的参数,现在dll可用于docker dotnet命令
 类似资料:
  • 对 YAML 定义的 Azure DevOps 管道进行更改时,将更改推送到分支只是为了看到生成失败并显示分析错误(YAML 有效,但管道定义无效),然后尝试试错解决问题,这可能会非常繁琐。 如果反馈循环可以通过本地分析和验证管道定义来缩短,那就太好了;基本上是一个了解Azure管道中可以定义的各种资源等的linter。但是,我还没有找到任何可以做到这一点的工具。 在某个地方有这样的工具吗?

  • 我有一个管道脚本,如下所示: ${build_type}可以是“发布”或“调试”。 当我的构建收到触发器时,我希望我的管道为${build_type}中的每个参数运行一次,然后向我发送一封电子邮件,其中包含有关两个构建的报告。 我怎样才能做到这一点? 我试图在编译阶段内定义一个并行块,并在那里设置build_type,但这并不能使其他阶段并行运行。

  • 我的 Jenkins 管道中有这个阶段: 在Jenkins"管理Jenkins"全局工具配置中,我有一个名为的Maven安装,版本。 运行此管道时,<code>mvnHome</code>为空,因为我在日志中得到了以下信息: 我确实在Jenkins服务器上找到了一个路径,它可以工作,但我不希望在此脚本中使用到mvn的硬编码路径。 我该如何解决这个问题? 编辑:答案摘要,使用。 我的工作代码现在是:

  • 我目前正在尝试在Azure运营模式服务器中设置一个包含多个工件的发布管道。第一个工件是从构建管道发布的,另一个工件是托管在Azure工件提要中的NuGet包。 当我创建和部署版本时,它成功下载了第一个工件,没有问题,当它继续下载NuGet包时,任务被标记为成功,但是它无法下载日志中包含以下内容的NuGet包。 知道会发生什么吗?

  • 这个问题看起来像是这个问题的重复。 我得到以下错误消息(在python sdk服务中): 我不知道日志记录或工件endpoint(等等)是什么通过检查源代码,似乎endpoint已经被硬编码到localhost中。

  • 问题内容: 我能够运行以下shell脚本,但无法从Jenkins管道代码运行。 尝试1。 输出: 尝试2: 尝试过sh“”“ 输出 : 美元符号后的非法字符串体字符;解决方案:要么转义文字美元符号,要么将值表达式括起来 有人能帮我吗? 问题答案: 这应该工作。 您还需要在调用下面的新subshel​​l时转义$