title: Windows shell command fails, but returns 0, when executed inside Jenkins pipeline
body: <p>In my Jenkins Pipeline I am executing a shell script in Windows CMD. The shell scrip itself calls Newman, which sends a request. The request fails. When I do this on my local computer, the %errorlevel% variable is set to 1.
  When I do it through the pipeline however, the &quot;%errorlevel&quot; stays 0, so the stage is marked as successful. In the log is visible that the call to Newman is executed exactly in the same way as on my own computer, the output from the Newman itself is the same, however for some reason the exit code from the shell command remains 0...
  What can be the reason for this and what is the correct way to fail the stage when the shell command does not succeed?</p>
  <pre><code>pipeline {
      agent any
  
      stages {
          stage('Stage 1') {
              steps {
                  echo 'Hello, Getting info from Git...'
                  git  url: 'https://mygitrepo.git'
              }
          }
          stage('Stage 2') {
              steps {
                  echo &quot;Current workspace is ${env.WORKSPACE}&quot;
                  bat encoding: 'UTF-8', script: 'forfiles /p collections /c &quot;cmd /c \\&quot;newman run @path -e \\&quot;..\\environment_config.json\\&quot; --bail\\&quot;&quot;'
                  bat &quot;echo %errorlevel%&quot; 
              }
          }
      }
  }
  </code></pre>
  <p>The pipeline log ending:</p>
  <pre><code>[Pipeline] bat
  
  C:\jenkins\workspace\PipelineGit&gt;echo 0 
  0
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  Finished: SUCCESS
  </code></pre>
  <p>The other thing, which puzzles me here is why in the log is printed <code>echo 0</code>, instead of <code>echo %errorlevel%</code> ?</p>
  <p><strong>Edit</strong>
  I changed the approach and now I am using a script section, instead of forfiles, which solves my problem:</p>
  <pre><code>stage('Stage 2') {
              steps {
                  echo &quot;Current workspace is ${env.WORKSPACE}&quot;
                  script {
                      def files = findFiles(glob: 'collections/**/*.json')
                      def file_names = []
                      for (def file : files) {
                          file_names.add(file.path)
                      }
                      
                      for (def filePath : file_names) {
                          bat encoding: 'UTF-8', script: &quot;newman run \&quot;${filePath}\&quot; -e \&quot;environment_config.json\&quot; -x --bail&quot;
                      }
                  }
              }
  </code></pre>