4

I'm scheduling my Jenkins jobs using groovy script:

def job = hudson.model.Hudson.instance.getJob("job")
def params = new StringParameterValue('PARAMTEST', "somestring")  
def paramsAction = new ParametersAction(params) 
def cause = new hudson.model.Cause.UpstreamCause(currentBuild)
def causeAction = new hudson.model.CauseAction(cause) 
def scheduledJob = hudson.model.Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)

Is there any way to retrieve the actual job link so I can be redirected within the console output to the job page?

Thanks!

  • When i Execute above mentioned groovy script, I'm getting below error ERROR: Build step failed with exception groovy.lang.MissingPropertyException: No such property: currentBuild for class: Script1 – user2439278 Feb 13 '20 at 15:25

1 Answers1

3

This will do the trick:

def url = scheduledJob.getFuture().waitForStart().getUrl()

If you need an absolute URL, prepend Jenkins.instance.getRootUrl() to that string.

Alex O
  • 7,746
  • 2
  • 25
  • 38
  • Here is a `Future` implementation of Jenkins: http://javadoc.jenkins.io/hudson/model/queue/FutureImpl.html Might not be clear, but if you want to wait for finalization of the job: `scheduledJob.getFuture().get();` – Nux Feb 20 '18 at 16:28