GeeDee
GeeDee

Reputation: 165

capture build number of downstream job in Jenkins code as pipeline

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

Upvotes: 3

Views: 1396

Answers (1)

jayhendren
jayhendren

Reputation: 4511

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.

Upvotes: 3

Related Questions