这是我的Jenkinsfile,我在Jenkins中安装了MSBuild插件。下面的msbuild命令是正确的,因为我可以从命令行运行它,但Jenkins一直在失败。如果我删除了它正在抱怨的参数,那么下一个参数会失败等等......
Jenkinsfile(保存在git存储库中):
pipeline {
agent {
docker 'node:7.7.3'
}
stages {
stage('Build') {
steps {
bat echo 'Checking node.js version..'
bat echo 'node -v'
bat echo 'Restore nugets..'
bat 'nuget restore mySolution.sln'
bat echo 'Building..'
bat "C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe" mySolution.sln /noautorsp /ds /nologo /t:clean,rebuild /p:Configuration=Debug /v:m /p:VisualStudioVersion=14.0 /clp:Summary;ErrorsOnly;WarningsOnly /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}
}
}
stage('Test') {
steps {
bat echo 'Testing..'
}
}
stage('Deploy') {
steps {
bat echo 'Deploying....'
}
}
}
post {
success {
bat echo 'Pipeline Succeeded'
}
failure {
bat echo 'Pipeline Failed'
}
unstable {
bat echo 'Pipeline run marked unstable'
}
}
}
错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 14: expecting '}', found '/' @ line 14, column 84.
\msbuild.exe" mySolution.sln /noautorsp
^
答案 0 :(得分:0)
问题是整个bat
参数需要用引号括起来,所以:
bat "'C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe' mySolution.sln /noautorsp /ds /nologo /t:clean,rebuild /p:Configuration=Debug /v:m /p:VisualStudioVersion=14.0 /clp:Summary;ErrorsOnly;WarningsOnly /p:ProductVersion=1.0.0.${env.BUILD_NUMBER}"
否则,它会将mySolution.sln
视为Groovy关键字,然后是/noautorsp
等。您还可以通过将其定义为Jenkins中的工具来避免MSBuild.exe的完整路径(通过MSBuild plugin),然后执行我在https://stackoverflow.com/a/45592810/466874所描述的内容。