Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 305
王子1986 Avatar asked May 26 '18 01:05

王子1986


2 Answers

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

like image 154
Vitalii Vitrenko Avatar answered Sep 21 '22 06:09

Vitalii Vitrenko


To add to Vitalii's answer, this is in case you're using Multibranch Pipeline Plugin:

def buildNumber = Jenkins.instance.getItem('jobName').getItem('branchName').lastSuccessfulBuild.number
like image 27
Florian Lauck Avatar answered Sep 18 '22 06:09

Florian Lauck