2017-04-04 124 views
0

這是我的Jenkinsfile,我在Jenkins中安裝了MSBuild插件。下面的msbuild命令是正確的,因爲我可以從命令行運行它,但Jenkins一直在失敗。如果我刪除它在抱怨那麼失敗就下單,等參數...Jenkins無法運行MSBuild命令

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

您可能需要避開斜槓。你可以嘗試在第14行的完整命令中加單引號嗎?像這樣:bat'command' –

+0

同樣的確切問題。 – Ninos

回答

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}" 

否則,它是TREA將mySolution.sln作爲Groovy關鍵字,然後/noautorsp等。您還可以通過將其定義爲Jenkins中的工具(通過MSBuild plugin),然後執行我在https://stackoverflow.com/a/45592810/466874處描述的內容,從而避免MSBuild.exe的完整路徑。