title: Verifying if an AWS Lambda function exists errors out Jenkins Pipeline with exit code 255
body: <p>I have a Jenkins pipeline where I need to check if an AWS Lambda function exists. During this check, you receive a 0 response if it is a function in AWS, and 255 if it isn't a function in AWS. But the script exits upon reaching this 255.</p>
  
  <p>I had seen code on here about ways to check if a function exists or not, and ended up pursuing the technique of checking the exit codes. However I need a way to catch this exit code without actually exiting the Jenkins pipeline script.</p>
  
  <p>For test purposes, testJenkins already exists in AWS Lambda, while testJenkins2 does not exist.</p>
  
  <pre><code>  agent any
    environment {
        PATH = "/var/lib/jenkins/aws:$PATH"
    }
  
    stages {
      stage('Checkout code') {
        steps {
          checkout scm
        }
      }
      stage('Zip up Lambda') {
          steps {
              dir('lambda/testJenkins') {
                  sh 'zip testJenkins.zip testJenkins.py'
              }
          }
      }
      stage('Upload to AWS') {
          steps {
            dir('lambda/testJenkins') {
              sh '''function does_lambda_exist() {
                aws lambda get-function --function-name $1 &gt; /dev/null 2&gt;&amp;1
                if [ 0 -eq $? ]; then
                  echo "Lambda '$1' exists"
                else
                  echo "Lambda '$1' does not exist"
                fi
              } &amp;&amp; does_lambda_exist testJenkins &amp;&amp; does_lambda_exist testJenkins2'''
              sh 'aws lambda create-function --zip-file fileb://testJenkins.zip --function-name testJenkins --runtime python3.7 --role &lt;role&gt; --handler testJenkins.lambda_handler'
            }
          }
      }
    }
  }
  </code></pre>
  
  <p>It should continue after the first test, but unfortunately exits right after receiving the exit code:</p>
  
  <pre><code>+ does_lambda_exist testJenkins
  + aws lambda get-function --function-name testJenkins
  + '[' 0 -eq 0 ']'
  + echo 'Lambda '\''testJenkins'\'' exists'
  Lambda 'testJenkins' exists
  + does_lambda_exist testJenkins2
  + aws lambda get-function --function-name testJenkins2
  [Pipeline] }
  [Pipeline] // dir
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 255
  Finished: FAILURE
  </code></pre>
  
  <p>Any help/better methods is greatly appreciated. New to Jenkins pipelines.</p>