如何修复 Jenkins 管道中与 SonarQube 一起使用的阶段

How to fix stage for use with SonarQube in JenkinsPipeline

我正在设置管道以对 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 
    }
}

然而,这失败了并且 returns 这个错误:

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:$

此错误表明它需要“}”,但我看不出它应该在哪里。花括号的嵌套似乎是正确的。

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

谢谢 埃里克

我认为您在 dotnet 前面缺少 shbat(或者 dotnet 是某个 jenkins 插件实现的 jenkins 管道步骤?) .

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

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