【问题标题】:Groovy compilation error for simple pipeline “unexpected token”简单管道“意外令牌”的 Groovy 编译错误
【发布时间】:2021-01-05 15:12:06
【问题描述】:

我有一个 Jenkinsfile 来使用 Sonarcube 执行代码分析。当我推送提交时,Jenkins 构建触发器但在 Jenkinsfile 中的以下行引发异常:

 -Dsonar.sources=. \

使用以下堆栈跟踪: 在耐久性级别运行:MAX_SURVIVABILITY org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: 工作流程脚本:21:意外令牌:。 @ 第 21 行,第 28 列。 -Dsonar.sources=。
^ 1 个错误

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)

这是我的 Jenkins 文件:

    pipeline {
            agent any
            stages {
                stage('Checkout'){
                    steps{
                        checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'Golide', url: 'https://github.com/Username/MyRepo.git']]])
                    }
                }
                stage('Build') {
                        steps {
                            bat "\"${tool 'MSBuild'}\" PaySys.sln /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /t:build /p:Configuration=Release /p:Platform=\"Any CPU\" /p:DeleteExistingFiles=True /p:publishUrl=c:\\inetpub\\wwwroot\\"
                        }
                }
                stage('Quality Gate') {
     steps {
       script {
       def MSBuildScannerHome = tool 'MSBuild_SonarScanner';
           withSonarQubeEnv("LocalSonar") {
           bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end"
           -Dsonar.projectKey=PaySys \
           -Dsonar.sources=. \
           -Dsonar.css.node=. \
           -Dsonar.host.url=http://localhost:9000 \
           -Dsonar.login=dgdhd6585gjgkgkfkfflf7584949"
               }
           }
       }
   }
            }
}

MSBuild_SonarScanner 指的是 Jenkins 的 SonarScanner for MSBuild 安装,LocalSonar 指的是 Jenkins 的 SonarQube 安装。 两个问题:

  1. 我的 groovy 脚本有什么问题?

  2. 我的配置是否足够/正确,足以触发代码分析

【问题讨论】:

  • 看来你需要在这里使用多行脚本语法。将你的 bat 脚本包装成 ''' 引号
  • 'bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end"'
  • 或者这个:' bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end" -Dsonar.projectKey=PaySys \ -Dsonar.sources=。 \ -Dsonar.css.node=。 \ -Dsonar.host.url=localhost:9000 \ -Dsonar.login=dgdhd6585gjgkgkfkfflf7584949" '

标签: jenkins groovy msbuild jenkins-pipeline


【解决方案1】:

看来您需要在此处使用多行脚本语法。将你的 bat 脚本包装成 ''' 引号:

bat '''${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end
           -Dsonar.projectKey=PaySys \
           -Dsonar.sources=. \
           -Dsonar.css.node=. \
           -Dsonar.host.url=http://localhost:9000 \
           -Dsonar.login=dgdhd6585gjgkgkfkfflf7584949'''

【讨论】:

    猜你喜欢
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多