title: Java: how to fail a Jenkins build deliberately?
body: <p>My test automation scripts have <code>setup()</code> and <code>tearDown()</code> methods. In my <code>setup()</code>, I have few pre-requisites specified which will require by rest of the tests.</p>
  
  <p>Now, in my <code>setup()</code> method I want to specify a function, which will fail the build if condition is not meeting.
  E.g. </p>
  
  <pre><code>   try {
          // To do 
      } catch (Exception e) {
            failJenkinsBuild();
      }
  </code></pre>
  
  <p>I have gone through couple of solution but none specifies how to do it in Java?</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/43399899/fail-a-jenkins-build-from-groovy-script">Fail a Jenkins build from groovy script</a></li>
  <li><a href="https://stackoverflow.com/questions/42667600/abort-current-build-from-pipeline-in-jenkins">Abort current build from pipeline in Jenkins</a></li>
  </ol>