Search code examples
jenkinsjenkins-pipelinejenkins-blueocean

How to get the build number of the parent build when restarting a build


I am using Jenkins Pipeline, Blue Ocean and I have Job "A".

I Built Job "A", So i have

Build Number 1
Build Number 2

I want to restart Build Number 2 ==> it will create Build Number 3.

So, Parent Build will be 2 and Child Build 3.

So, How can print Parent Build number?

For example in Build 3 will print 2.

So, Is their env Variable that held the Parent Build Number ?


Solution

  • I made an work around using groovy Regular Expressions - regexes to grep build logs, looking for " Restarted from build #\d ".

    If i found it, it means that build is restarted and if not that's mean it is a new build not depending on another build .

    Is their another solution ? 

    because i think my solution is not the best and may be standard of logs will be changed in the future