capture build number of downstream job in Jenkins code as pipeline

Viewed 1027

Is there an environment variable that captures the downstream job's build number ? I am using build step in pipeline as code.

1 Answers

Not an environment variable, but an object property:

downstreamBuild = build 'myDownstreamJob'
downstreamBuildNumber = downstreamBuild.rawBuild.id

Note that you will either need to disable the Groovy sandbox or get script approvals in order to use rawBuild. Also, you cannot use wait: false with your build step, since build() returns null when called with wait: false.

Related