This plugin executes the supplied Groovy code, every time an event is triggered. You can use @Grab annotations if you'd like to import external dependencies.


This plugin injects the following variables, which can be used in your Groovy code.

Additionally, if you return a java.util.Map object, these variables will be added to the context for any future code invocations.

Name Description Class
log The plugin's logger instance. java.util.Logger
context A map containing variables, which are persisted between code executions. java.util.Map
event The name of the event that triggered the code (see Events below). java.lang.String
jenkins The Jenkins instance. jenkins.model.Jenkins
env (Optional) The environment variables used for a job instance. hudson.EnvVars
run (Optional) The run object associated with a job instance. hudson.model.Run
listener (Optional) The task listener associated with a job instance. hudson.model.TaskListener


This Groovy code is executed when any of the below events occur.

Name Description
GlobalEventsPlugin.start Called when the plugin is started.
GlobalEventsPlugin.stop Called when the plugin is stopped.
GlobalEventsPlugin.schedule Called every $scheduledTime minutes.
RunListener.onStarted Called when a build is started (i.e. it was in the queue, and will now start running on an executor).
RunListener.onCompleted Called after a build is completed.
RunListener.onFinalized Called after a build is moved to the Run.State.COMPLETED state.
RunListener.onDeleted Called right before a build is going to be deleted.
ComputerListener.onLaunchFailure Called when the agent fails to connect.
ComputerListener.onOnline Called when a node comes online.
ComputerListener.onOffline Called when a node goes offline.
ComputerListener.onTemporarilyOnline Called when a node is marked temporarilyOnline by a user.
ComputerListener.onTemporarilyOffline Called when a node is marked temporarilyOffline by a user.
QueueListener.onEnterWaiting Called when a job enters the queue.
QueueListener.onEnterBlocked Called when a job isn't ready to start for some reason other than executor availability.
QueueListener.onEnterBuildable Called when a queued job is ready to run when an executor is available.
QueueListener.onLeft Called when a job leaves the queue after starting or being cancelled.
ItemListener.onCreated Called after a new job is created and added to Jenkins, before the initial configuration page is provided.
ItemListener.onCopied Called after a new job is created by copying from an existing job.
ItemListener.onDeleted Called right before a job is going to be deleted.
ItemListener.onRenamed Called after a job is renamed.
ItemListener.onLocationChanged Called after an item's fully-qualified location has changed.
ItemListener.onUpdated Called after a job has its configuration updated.

There is also an Event class (automatically imported) which contains constants for all of the available event names.


To configure a logger for this plugin, use the logging filter org.jenkinsci.plugins.globalEventsPlugin.