title: Jenkins retrieve details of last successful build
body: <p>I have jenkins pipeline (Jenkinsfile) for build process, which setup build version number for each build once its successful. Now want to retrieve details like <code>currentBuild.displayName</code> of previous successful build in jenkinsfile and increment current builds build number.</p>
  
  <p>I don't want to use Jenkins build number, because failed build numbers are wasted if I use Jenkins Build number.</p>
  
  <p>Can get this with groovy <code>def buildName = Jenkins.instance.getItem('Gateway').lastSuccessfulBuild.displayName</code></p>
  
  <p>But how can I run it in <code>Jenkinsfile</code> ?</p>