如何在Jenkins中修复与SonarQube一起使用的平台

时间:2019-05-07 13:56:35

标签: sonarqube jenkins-pipeline

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

此错误表示正在期待'}',但我不知道该在哪里。花括号的嵌套似乎是正确的。

有人可以帮助我理解此错误吗?

谢谢 埃里克

1 个答案:

答案 0 :(得分:1)

我认为您在sh前面缺少batdotnet(或者dotnet是由某些jenkins插件实现的jenkins管道步骤吗?)。 / p>

假设您的dotnet是为Linux奴隶上的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"
    }
}