Jenkins Pipeline script - return value of a build step

Viewed 4670

Is there a way to fetch URL of a build step (without waiting for completion) through Jenkins pipeline script?

Here is what I've tried but the return value of build is null.

def build_job = build job: 'dummy_job', wait: false

Trying to fetch URL as follows: build_job.absoluteUrl

2 Answers

You can get it by using the getRawBuild() method:

   def build_job=build(job:'dummy_job',propagate:false)
   echo build_job.getResult()
   echo build_job.getRawBuild().getAbsoluteUrl()

Don't use the wait: false since the function won't return the expected result. don't use the propagate: false so the job won't fail before the next step if the called job fails.

BUILD_URL should provide you the job url. You can get all environment variables in the pipeline using env bash command.

Jenkins doc: here

Related