Saravanan Jothilingam
Saravanan Jothilingam

Reputation: 99

Jenkins Pipeline: Get the build url and build number and print that in post action method

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"     
    }
}

Upvotes: 1

Views: 2744

Answers (1)

Unforgettable631
Unforgettable631

Reputation: 1020

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.

Upvotes: 1

Related Questions