How to get only the Full name of previous Jenkins build

907 Views Asked by At

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.

1

There are 1 best solutions below

0
Siddharth Kaul On

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