title: Jenkins and return code from windows batch
body: <p>I using a Jenkins (on a windows machine) job to compile some code for different targets via Ant.
  For doing so, I wrap the call to the ant target within a (windows) batch loop like this:</p>
  
  <pre><code>@echo off
  for %%t in (target1 target2 target3) do (
    ant -f build.xml build -DPARAM_TARGET=%%t
  )
  </code></pre>
  
  <p>That was my first idea ... but this codes leads to an successful build even if (e.g.) target1 failed. So I put some more lines to the windows batch build step to get more overview. Also I have checekdout the code to get the same workingspace than Jenkins has to my local machine and add an test.bat to check the windows batch code can work at all.</p>
  
  <pre><code>@echo off
  for %%t in (target1 target2 target3) do (
    ant -f build.xml build -DPARAM_TARGET=%%t
    echo ELVL: %ERRORLEVEL% 
    IF NOT %ERRORLEVEL% == 0 ( 
      echo ABORT: %ERRORLEVEL%
      exit /b %ERRORLEVEL%
    ) ELSE (
      echo PROCEED: %ERRORLEVEL%
    )
  )
  </code></pre>
  
  <p>Testing this on my local windows machine shows the expected behaviour - here on success:</p>
  
  <pre><code>BUILD SUCCESSFUL
  Total time: 3 seconds
  ELVL: 0
  PROCEED: 0
  </code></pre>
  
  <p>And on failure:</p>
  
  <pre><code>BUILD FAILED
  C:\Work\...
  C:\Work\...
  
  Total time: 0 seconds
  ELVL: 9009
  ABORT: 9009
  </code></pre>
  
  <p>The same code on Jenkins do this:</p>
  
  <pre><code>BUILD FAILED
  C:\Work\...
  C:\Work\...
  
  Total time: 4 seconds
  ELVL: 0
  PROCEED: 0
  </code></pre>
  
  <p>After using google for a while it reveals, that the return code from calling the Ant target is not properly passed to the java enviornment wherefrom Jenkins do the calls. I have tested around using "call" or "set ERRORLEVEL=1" something like this, but haven't found a soloution yet.</p>
  
  <p>Anyone has an idea?
  Put the loop (target1-3) into a system groovy script and hande the callc manually - does that work?</p>
  
  <p>Regards</p>