title: Jenkins pipeline is skipping groovy 'else if' clause
body: <p>I am conducting some tests in my pipeline. My aim is that if an error file exists the build should fail. But if for some reason the tests experienced an exception and didn't write either an error or successful file, the pipeline should also fail. If neither of the conditions for failure are met, I would like the an upstream job to execute.</p>
  
  <p>I wrote it in stage and initially it looked like this:</p>
  
  <pre><code>stage('system tests') {
      steps {
          dir(project_root) {
              def error_exists = sh(
                  script: 'ls error.txt', returnStatus: true
              )
              if (error_exists == 0) {
                  currentBuild.result = 'FAILED'
                  return
              }
              build job: 'my-job;
          }
      }
  }
  </code></pre>
  
  <p>The above code works. When the tests being executed wrote an error file, the pipeline fails. I then tried to modify the code to cater for the outcome where neither error or success files are written. </p>
  
  <pre><code>stage('system tests') {
      steps {
          dir(project_root) {
              def error_exists = sh(
                  script: 'ls error.txt', returnStatus: true
              )
              def success_exists = sh(
                  script: 'ls success.txt', returnStatus: true
              )
              if (error_exists == 0) {
                  currentBuild.result = 'FAILED'
                  return
              } else if (success_exists == 1 &amp;&amp; error_exists == 1) {
                  currentBuild.result = 'FAILED'
                  return
              }
              build job: 'my-job;
          }
      }
  }
  </code></pre>
  
  <p>I simulated a situation where neither file was written and the pipeline didn't fail, and instead it triggered the upstream build. Why am I not entering the <code>else if</code> clause` if the result of both shell scripts is false? I took the logical operators from <a href="https://www.tutorialspoint.com/groovy/groovy_logical_operators.htm" rel="nofollow noreferrer">here</a> and I think they should be met (The code below is output from the shell scripts in the new-job pipeline)</p>
  
  <pre><code>[new-job] Running shell script
  + ls error.txt
  ls: cannot access error.txt: no such file or directory
  
  [new-job] Running shell script
  + ls success.txt
  ls: cannot access success.txt: no such file or directory
  </code></pre>