title: Jenkins pipeline sh step not returning different status code
body: <p>I have the following code inside the pipeline</p>
  
  <pre><code>def deploy(branch='master', repo='xxx'){
      if (env.BRANCH_NAME.trim() == branch) {
          def script = libraryResource 'build/package_indexes/python/build_push.sh'
          env.PYPI_REPO = repo
          sh script
      }else {
          echo "Not pushing to repo because branch is: "+env.BRANCH_NAME.trim()+" and not "+branch
      }
  }
  </code></pre>
  
  <p>And the script looks like this:</p>
  
  <pre><code>if [ -f "setup.cfg" ]; then
    # only build a wheel if setup.cfg exists, so we can disable wheel build if need be
    echo "Build package ${PACKAGE_NAME} tar.gz and wheel, and push to jfrog repo: $PYPI_REPO"
    python setup.py sdist upload -r jfrog
    echo "status code: $?"
  fi
  </code></pre>
  
  <p>When I execute the script directly in shell:</p>
  
  <p><code>sh push.sh</code></p>
  
  <p>It returns the status code 1 when failed to push to the repo, see output:</p>
  
  <pre><code>Submitting dist/xxx-xxxx-0.0.7.tar.gz to https://xxx.jfrog.io/xxx/xxx-pypi/
  Upload failed (405): Method Not Allowed
  error: Upload failed (405): Method Not Allowed
  status code: 1
  </code></pre>
  
  <p>But when I execute the pipeline in Jenkins, the status code is 0 when failed to push to the repo:</p>
  
  <pre><code>Submitting dist/xxx-xxxx-0.0.7.tar.gz to https://xxx.jfrog.io/xxx/xxx-pypi/
  Upload failed (403): Forbidden
  + echo status code: 0
  status code: 0
  </code></pre>
  
  <p>How do I make it to return status code 1 when it fails in Jenkins job?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Looks like the problem is not inside Jenkins, I can replicate the same problem on the shell of the Jenkins server.</p>