'How to get only the Full name of previous Jenkins build

I would like to send the full name of the previous build that was received by using the following:

Run previousBuild = steps.currentBuild.rawBuild.getPreviousBuildInProgress()

in order to send to getItemByFullName as you can see below,

Jenkins.instance.getItemByFullName(previousBuildPath)

I tried to find it in the Run class hudson Documentation with no success.

while printing previousBuild I got the name with the build number like:

 previousBuild- > project_neme/build_name #100

But I want to get only the name with no String substring cutting.



Solution 1:[1]

You are looking for display name property. Display name is the name given to each build (if you update it during execution) followed by a build number. The display name will only return the build name. Jenkins.instance.getItemByFullName('JobName').getLastBuild().displayName

Read here https://javadoc.jenkins.io/hudson/model/Job.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Siddharth Kaul