sudhir
sudhir

Reputation: 309

how to get build number of other job in jenkins pipeine

I have created a pipeline where for build there is one job and for mail notification another job. I need to get the build job latest BUILD_NUMBER(either success or failure whatever) in mail notification job and i should publish the build job latest url as a mail notification regarding the buildstatus. How could i achieve this?

Upvotes: 1

Views: 4724

Answers (1)

Corey Olson
Corey Olson

Reputation: 61

I think there are multiple ways that you could achieve this. Let's call your 2 builds A (build) and B (mail notification).

  1. Call B from A; pass whatever information you need in B as a parameter
  2. You can use a combination of this script and the Job API.

For #2, I'm thinking you would have something like this in your B job:

def jobname = "<name of Job A>"
def job = Jenkins.instance.getItemByFullName(jobname)
def build = job.getLastBuild()

Upvotes: 3

Related Questions