1
votes

I have one pipeline job where it executes multiple jobs say job1 and job2. Once the execution is complete, i need to get the job2's build url and its build number and put that in the post section of success.

How to achieve this? Pls share your inputs.

Stages
{
    Stage A
    {
       build 'job1'
    }

    stage B
    {
       build 'job2'
     }
}

post 
{
    success 
    {
      mail to: "${EMAIL_LIST}",
      subject: 'Test Pipeline - SUCCESS',
      body: " Get job-2's build_url and build_number"     
    }
}
1

1 Answers

1
votes

You can try something like this if you start downstream jobs and wait for result of those:

def job1 = build job: 'myJob', wait: true
def job1Result = "${job1.getId()}"
def job1Url = "${job1.getAbsoluteUrl()}"

and use these into your post build action. I'm not using declarative pipeline but scripted pipeline. Be aware where you define the vars if you want them to be available on post build step.

Ps. I see that it's discouraged to use getAbsoluteUrl, but you can read documentation via the link below. See for all options Run.