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

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

It's so annoying to get approvals in enterprise environment(a lot of request and approvals) So I am using following API way to get the latest build number.

import groovy.json.JsonSlurperClassic
httpRequest url: 'https://jenkinsurl.local/job/Build/api/json', outputFile: 'output.json'

def jsonFile = readFile(file: 'output.json')
def data = new JsonSlurperClassic().parseText(jsonFile)
latestBuildNumber = "${data.lastSuccessfulBuild.number}"

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