jenkins - 简单管道“意外令牌”的 Groovy 编译错误
问题描述
我有一个 Jenkinsfile 来使用 Sonarcube 执行代码分析。当我推送提交时,Jenkins 构建触发器但在 Jenkinsfile 的以下行中引发异常:
-Dsonar.sources=. \
具有以下堆栈跟踪:在耐久性级别运行:MAX_SURVIVABILITY org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:WorkflowScript: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)
这是我的 Jenkinsfile :
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 用于 MSBuild 安装,LocalSonar 指的是 Jenkins 的SonarQube 安装。两个问题:
我的 groovy 脚本有什么问题?
我的配置是否足够/正确,足以触发代码分析
解决方案
看起来您需要在这里使用多行脚本语法。将您的 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'''
推荐阅读
- python - 如何使用noise.py 模块选择种子
- python - 将分隔符上的多列拆分为熊猫数据框中的行
- laravel - 模型关系创建在 Laravel 中使用了错误的字段
- javascript - Javascript中的多维数组比较
- java - Java - 使用机器人类截取的屏幕截图具有不同的字节数
- php - 如何在 laravel 5.5 控制器中完全注销?
- javascript - 试图在javascript中添加数字
- wordpress - wordpress 中的 wp-admin 与 wp-login
- java - 使用 PHP、JSON 和 MySQL 的 Android 身份验证
- react-native - 在 React Native 中使用 Detox 测试 Picker