title: Avoid early exit from command in gitlab CI script pipeline while still capturing exit status
body: <p>I am trying to generate a badge from PyLint output in a Gitlab CI script. Eventually, the job should fail if PyLint has a non-zero exit code. But before it does so, I want the badge to be created. So I have tried the following:</p>
  
  <pre><code>before_script:
      - [...]
      - mkdir -p public
  script:
      - pylint lib --disable R,missing-docstring,wrong-import-order --reports=y | tee public/pylint-report.txt
      - export SUCCESS=${PIPESTATUS[0]}
      - SCORE=$(tail -n 2 public/pylint-report.txt | grep -o -P "\d\d?\.\d+\/\d*" | head -1)
      - echo "PyLint score ${SCORE}"
      - python3.6 -m pybadges --left-text=PyLint --right-text=${SCORE} &gt; public/pylint.svg
      - exit ${SUCCESS}
  artifacts:
      when: always
      [...]
  </code></pre>
  
  <p>This works fine if the PyLint exit code is 0:</p>
  
  <pre><code>$ mkdir -p public
  $ pylint lib --disable R,missing-docstring,wrong-import-order --reports=y | tee public/pylint-report.txt; export SUCCESS=${PIPESTATUS[0]}
  [Pylint report output]
  $ SCORE=$(tail -n 2 public/pylint-report.txt | grep -o -P "\d\d?\.\d+\/\d*" | head -1)
  $ echo "PyLint score ${SCORE}"
  PyLint score 10.00/10
  $ python3.6 -m pybadges --left-text=PyLint --right-text=${SCORE} &gt; public/pylint.svg
  $ exit ${SUCCESS}
  Uploading artifacts...
  public/pylint-report.txt: found 1 matching files   
  public/pylint.svg: found 1 matching files          
  Uploading artifacts to coordinator... ok            id=XXX responseStatus=201 Created token=XXX
  Job succeeded
  </code></pre>
  
  <p>However, when PyLint exits with non-zero, the script is aborted after the first line:</p>
  
  <pre><code>$ mkdir -p public
  $ pylint lib --disable R,missing-docstring,wrong-import-order --reports=y | tee public/pylint-report.txt
  [Pylint report output]
  Uploading artifacts...
  public/pylint-report.txt: found 1 matching files   
  WARNING: public/pylint.svg: no matching files      
  Uploading artifacts to coordinator... ok            id=XXX responseStatus=201 Created token=XXX
  ERROR: Job failed: exit code 1
  </code></pre>
  
  <p>To clarify: I want the job to fail, but I want to make sure the script always runs all the lines. Only the <code>exit</code> command in the last line should determine the job status.</p>
  
  <p>This runs in a container that uses the Bash.</p>
  
  <p>I expected the <code>tee</code> command to always exit with 0 so that the first script line should never fail. But that does not seem to be the case.</p>
  
  <p>I have tried appending a <code>|| true</code> call to the first line, but then the following line, <code>SUCCESS=${PIPESTATUS[0]}</code>, is always 0; perhaps this refers to the root cause.</p>
  
  <p>Also, I have tried to append the <code>export</code> call (now second line) to the first line, separated by a semicolon. Again, no difference even though I also expected the <code>export</code> call always to exit with 0.</p>
  
  <p>My question is hence: why can the first line of the script exit with a non-zero code? How do I prevent this?</p>
  
  <p>Or maybe: is there an easier way to achieve the same goal?</p>