Search code examples
jenkinsjenkins-pipeline

How to get latest build number from another job in jenkins pipeline


I am using jenkins pipeline 2.0, and I would like to get another job's latest successful build number.

What's the pipeline syntax to use?


Solution

  • You can get it this way

    def buildNumber = Jenkins.instance.getItem('jobName').lastSuccessfulBuild.number
    

    If you get a RejectedAccessException you will have to approve those methods, see In-process Script Approval