首页 > 解决方案 > 如何在 JenkinsPipeline 中修复与 SonarQube 一起使用的阶段

问题描述

我正在设置我的管道以对 dotnet 项目进行 SonarQube 扫描。这是阶段:

stage('SonarQube analysis') {
    withSonarQubeEnv('My Sonar') {
        dotnet "/usr/local/sonar-scanner-msbuild/SonarScanner.MSBuild.dll" begin /k:${SONARQUBEPROJECTKEY}
        dotnet build "src/hub-backend.sln"
        dotnet "/usr/local/sonar-scanner-msbuild/SonarScanner.MSBuild.dll" end 
    }
}

但是,这会失败并返回此错误:

Obtained Jenkinsfile from git https://<removed>/scm/<removed>/jenkins-stuff.git
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 30: expecting '}', found 'begin' @ line 30, column 84.
   ild/SonarScanner.MSBuild.dll" begin /k:$

这个错误表明它期待'}',但我不知道那会在哪里。花括号的嵌套似乎是正确的。

有人可以帮我理解这个错误吗?

谢谢埃里克

标签: sonarqubejenkins-pipeline

解决方案


我认为您缺少shorbat前面的dotnet(或者是dotnet一些詹金斯插件实现的詹金斯管道步骤?)。

假设您dotnet是在您的 linux slave 上为您 jenkins 用户安装的命令。

stage('SonarQube analysis') {
    withSonarQubeEnv('My Sonar') {
        sh "dotnet \"/usr/local/sonar-scanner-msbuild/SonarScanner.MSBuild.dll\" begin /k:${SONARQUBEPROJECTKEY}"
        sh "dotnet build \"src/hub-backend.sln\""
        sh "dotnet \"/usr/local/sonar-scanner-msbuild/SonarScanner.MSBuild.dll\" end"
    }
}

推荐阅读