I have created a Groovy script which is used in a System Groovy Script
step in a Jenkins job which needs to access the current build of the current job.
T
This is the snippet I have been looking for!
import hudson.model.*
def currentBuild = Thread.currentThread().executable
This fits in with my above script like so:
import hudson.model.*
def scheduleDependentJob(jobName) {
def fooParam = new StringParameterValue('foo', 'bar');
def paramsAction = new ParametersAction(fooParam)
println "Scheduling dependent job"
def currentBuild = Thread.currentThread().executable
def cause = new Cause.UpstreamCause(currentBuild)
def causeAction = new hudson.model.CauseAction(cause)
instance.queue.schedule(job, 0, causeAction, paramsAction)
}