title: Get previous build result
body: <p>I want to emulate the original Jenkins behaviour of doing stuff (like sending out notifications) when builds become unstable / fail or become successful again.</p>
  
  <p>For that I need to query the previous build status, which can be done like this:</p>
  
  <pre><code>currentBuild.rawBuild.getPreviousBuild()?.getResult().toString()
  </code></pre>
  
  <p>However, <code>rawBuild</code> is supposed to be a "dangerous" object and as thus blacklisted and <a href="https://issues.jenkins-ci.org/browse/JENKINS-28178" rel="nofollow">cannot be executed inside the Groovy sandbox</a>.</p>
  
  <p>Now, since I'm loading my Jenkins scripts from SCM, there is no way for me to deactivate the Groovy sandbox on a per-project level, but only for the whole Jenkins instance (i.e. <a href="https://wiki.jenkins-ci.org/display/JENKINS/Permissive+Script+Security+Plugin" rel="nofollow">through this</a>), and this is certainly not something I want.</p>
  
  <p>Is there any other way of determining the last build status of a job that conforms with the sandbox principles (and does not include hacks like querying the status via Jenkins' REST API) that I have missed?</p>