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

Variables:

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 EnvVars for a job instance. hudson.EnvVars
run (Optional) The run object associated with this job instance. hudson.model.Run
listener (Optional) The task listener associated with the job instance. hudson.model.TaskListener


Events:

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

Name Description
GlobalEventsPlugin
GlobalEventsPlugin.start Called when the plugin is started.
GlobalEventsPlugin.stop Called when the plugin is stopped.
GlobalEventsPlugin.schedule Called every $scheduledTime minutes.
RunListener
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
ComputerListener.onLaunchFailure Called when the slave 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
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


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

Logging:

To configure a logger, use the logging filter "org.jenkinsci.plugins.globalEventsPlugin".