Jenkins无法运行MSBuild命令

时间:2017-04-04 23:02:23

标签: jenkins msbuild jenkins-pipeline

这是我的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
                                 ^

1 个答案:

答案 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所描述的内容。