title: Jenkins not reading ERRORLEVEL
body: <p>I am testing a simple build process in Jenkins; The Build section has Execute Windows batch command</p>
  
  <pre><code>echo %ERRORLEVEL%
  cscript C:\Users\user\Documents\test.vbs
  echo %ERRORLEVEL%
  </code></pre>
  
  <p>My test.vbs does nothing except set the <code>ERRORLEVEL</code> environment variable; I also tried using <code>wscript.quit</code> to see if that had an effect on <code>ERRORLEVEL</code></p>
  
  <pre><code>dim wShell
  dim wSysEnv
  
  set wShell = Wscript.CreateObject("WScript.Shell")
  set wSysEnv = wShell.Environment("SYSTEM")
  
  WScript.Echo "ERRORLEVEL=" &amp; wSysEnv( "ERRORLEVEL" )
  wSysEnv( "ERRORLEVEL" ) = 0
  WScript.Echo "ERRORLEVEL=" &amp; wSysEnv( "ERRORLEVEL" )
  wSysEnv( "ERRORLEVEL" ) = 2
  WScript.Echo "ERRORLEVEL=" &amp; wSysEnv( "ERRORLEVEL" )
  WScript.Quit 3
  </code></pre>
  
  <p>There is no post build action
  The console output is as follows:</p>
  
  <pre><code>Started by user anonymous
  Building in workspace C:\Program Files (x86)\Jenkins\jobs\TADS Host-Agent client\workspace
  [workspace] $ cmd /c call C:\Users\user\AppData\Local\Temp\hudson4571524647235360597.bat
  
  C:\Program Files (x86)\Jenkins\jobs\TADS Host-Agent client\workspace&gt;echo 1 
  1
  
  C:\Program Files (x86)\Jenkins\jobs\TADS Host-Agent client\workspace&gt;cscript C:\Users\user\Documents\test.vbs 
  Microsoft (R) Windows Script Host Version 5.8
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  ERRORLEVEL=0
  ERRORLEVEL=0
  ERRORLEVEL=2
  
  C:\Program Files (x86)\Jenkins\jobs\TADS Host-Agent client\workspace&gt;echo 1 
  1
  
  C:\Program Files (x86)\Jenkins\jobs\TADS Host-Agent client\workspace&gt;exit 1 
  Build step 'Execute Windows batch command' marked build as failure
  Finished: FAILURE
  </code></pre>
  
  <p>As shown in the output above, the <code>ERRORLEVEL</code> before I start the script is 1.
  The script successfully sets <code>ERRORLEVEL</code> to 2 and exits with a code of 3. However when I check the <code>ERRORLEVEL</code> at the end of the script, it is back to 1 as it started.</p>
  
  <p>I found some pages that said environment variables are only set for the current process and any child process; that is they are session environment variables.</p>
  
  <p>In which case how can <code>ERRORLEVEL</code> be set for Jenkins to report a test as success or failure? It doesn't appear to check the variable during runtime, only at the start of the execution of the script. This is not useful as the script may change the value of the variable.</p>