title: How to fix 'Java ... was unexpected at this time' when invoking VS 2017 build tools from Jenkins?
body: <p>I have Jenkins freestyle jobs that successfully invoke msbuild jobs using the VS 2015 tools by declaring environment variable:</p>
  
  <pre><code>VSMSBUILDCMD_14_0="C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\VsMSBuildCmd.bat"
  </code></pre>
  
  <p>and setting the environment by calling from a bat step:</p>
  
  <pre><code>call %VSMSBUILDCMD_14_0%
  </code></pre>
  
  <p>However, if I try to do similar using the VS 2017 tools I get an expected error:</p>
  
  <pre><code>VSMSBUILDCMD_14_1="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\Tools\\VsMSBuildCmd.bat"
  
  call %VSMSBUILDCMD_14_1%
  
  c:\jenkins\workspace\aa_test&gt;call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat"
  
  \Java\jre1.8.0_161\bin"" was unexpected at this time.
  </code></pre>
  
  <p>I get the same result even if I use shortened directory names:</p>
  
  <pre><code>VSMSBUILDCMD_14_1="C:\\PROGRA~2\\MIB055~1\\2017\\BuildTools\\Common7\\Tools\\VsMSBuildCmd.bat"
  
  CALL %VSMSBUILDCMD_14_1%
  
  CALL "C:\PROGRA~2\MIB055~1\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat" 
  \Java\jre1.8.0_161\bin"" was unexpected at this time.
  </code></pre>
  
  <p>This question may be related: <a href="https://stackoverflow.com/questions/28562559/how-to-solve-jdk-issue-unexpected-at-this-time">How to solve JDK issue unexpected at this time</a></p>
  
  <p>but I haven't managed to fix my problem.</p>
  
  <p>Any suggestions please?</p>