title: Aborting a Jenkins job from within the executing shell
body: <p>First some context:</p>
  
  <p>Currently I have a Jenkins job setup to run a perl script, that in turns builds source code on whatever machine it is running.</p>
  
  <p>From my observation of the Jenkins behaviour, if I abort a running Jenkins job from the UI all the associated threads (single or parallel) of my perl script are killed on the respective slave machine.</p>
  
  <p>Now what I would like to replicate that behaviour ie abort a Jenkins job IF during my build step my script produces some errors. Unfortunately I am not able to easily modify or update the perl script that is being launched (I am not the owner) so I have to find a solution that would need minimal modification the perl script itself, if possible of course.</p>
  
  <p>The reason I need it to be aborted is because we do not want to build any down stream dependencies after the area/repos/location where an error has been produced.</p>
  
  <p>Would I be able to automate this type of behaviour? Maybe by scanning the logs of the perl script in search of error? Or something of the sort?</p>
  
  <p>Any leads would be much appreciated.</p>
  
  <p>Do let me know if more information/clarification is needed.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>I found an interesting solution that actually aborts the job. By running the following command:</p>
  
  <pre><code>curl --request POST  -u &lt;username&gt;:&lt;password&gt; "%JENKINS_URL%/job/%JOB_NAME%/lastBuild/stop"
  </code></pre>
  
  <p>Of course, I would now have to figure a way to launch this command whenever any errors are found in the areas that are currently being compiled.</p>
  
  <p>I feel like I am half way though.</p>