Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

Example to show some variables available to the system Groovy script

println "build.inspect() = " + build.inspect()
println "build.dump() = " + build.dump()
println "listener.inspect() = " + listener.inspect()
println "listener.dump() = " + listener.dump()

println "environment=" + build.getEnvironment(listener).dump()
println "JENKINS_HOME=" + build.getEnvironment(listener).get('JENKINS_HOME')

println "myVar=$myVar"
println "myVar=${myVar}"

This shows how to get a parameter if your job is parameterized

import jenkins.model.Jenkins
import hudson.model.Run
import hudson.model.ParametersAction

static def getParameter(parameters, paramName) {
    // The first instance found by parameters.find that matches paramName will cause the value of that instance to be returned
    parameters.find { it.name == paramName }?.value

static def getParameters(Run build) {
    build?.allActions?.find { it instanceof ParametersAction }?.parameters;

println getParameter(getParameters(build), "myParameter")

An example of finding all pipeline jobs. It requires the pipeline plugin to be installed.

import jenkins.model.Jenkins
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.job.WorkflowRun

(Jenkins.get().items?.findAll {
    it instanceof WorkflowJob
}?.findAll {
}).each { WorkflowJob job ->
    job.builds.each { WorkflowRun build ->
  • No labels