Package hudson.triggers
Class Trigger<J extends Item>
- java.lang.Object
-
- hudson.triggers.Trigger<J>
-
- All Implemented Interfaces:
ExtensionPoint
,Describable<Trigger<?>>
- Direct Known Subclasses:
ReverseBuildTrigger
,SCMTrigger
,TimerTrigger
public abstract class Trigger<J extends Item> extends Object implements Describable<Trigger<?>>, ExtensionPoint
Triggers aBuild
.To register a custom
Trigger
from a plugin, putExtension
on yourTriggerDescriptor
class.- Author:
- Kohsuke Kawaguchi
- See Also:
TriggeredItem
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Trigger.Cron
Runs every minute to checkTimerTrigger
and schedules build.-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
Fields Modifier and Type Field Description static long
CRON_THRESHOLD
Used to be milliseconds, now is seconds since Jenkins 2.289.protected J
job
protected String
spec
protected CronTabList
tabs
static Timer
timer
Deprecated.UseTimer.get()
instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DescriptorExtensionList<Trigger<?>,TriggerDescriptor>
all()
Returns all the registeredTrigger
descriptors.static void
checkTriggers(Calendar cal)
static List<TriggerDescriptor>
for_(Item i)
Returns a subset ofTriggerDescriptor
s that applies to the given item.TriggerDescriptor
getDescriptor()
Gets the descriptor for this instance.Action
getProjectAction()
Deprecated.as of 1.341 UsegetProjectActions()
instead.Collection<? extends Action>
getProjectActions()
Action
s to be displayed in the job page.String
getSpec()
Gets the crontab specification.protected Object
readResolve()
void
run()
Executes the triggered task.void
start(J project, boolean newInstance)
Called when aTrigger
is loaded into memory and started.void
stop()
Called before aTrigger
is removed.
-
-
-
Field Detail
-
spec
protected final String spec
-
tabs
protected transient CronTabList tabs
-
CRON_THRESHOLD
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @RestrictedSince("2.289") public static long CRON_THRESHOLD
Used to be milliseconds, now is seconds since Jenkins 2.289.
-
timer
@Deprecated @CheckForNull public static Timer timer
Deprecated.UseTimer.get()
instead.This timer is available for all the components inside Hudson to schedule some work. Initialized and cleaned up byJenkins
, but value kept here for compatibility. If plugins want to run periodic jobs, they should implementPeriodicWork
.
-
-
Constructor Detail
-
Trigger
protected Trigger(@NonNull String cronTabSpec)
Creates a newTrigger
that getsrun
periodically. This is useful when your trigger does some polling work.- Parameters:
cronTabSpec
- the crontab entry to be parsed- Throws:
IllegalArgumentException
- if the crontab entry cannot be parsed
-
Trigger
protected Trigger()
Creates a newTrigger
without using cron.
-
-
Method Detail
-
start
public void start(J project, boolean newInstance)
Called when aTrigger
is loaded into memory and started.- Parameters:
project
- given so that the persisted form of this object won't have to have a back pointer.newInstance
- True if this may be a newly created trigger first attached to theProject
(generally if the project is being created or configured). False if this is invoked for aProject
loaded from disk.- See Also:
Items.currentlyUpdatingByXml()
-
run
public void run()
Executes the triggered task. This method is invoked whenTrigger(String)
is used to create an instance, and the crontab matches the current time.Maybe run even before
start(hudson.model.Item, boolean)
, prepare for it.
-
stop
public void stop()
-
getProjectAction
@Deprecated public Action getProjectAction()
Deprecated.as of 1.341 UsegetProjectActions()
instead.
-
getProjectActions
public Collection<? extends Action> getProjectActions()
Action
s to be displayed in the job page.- Returns:
- can be empty but never null
- Since:
- 1.341
-
getDescriptor
public TriggerDescriptor getDescriptor()
Description copied from interface:Describable
Gets the descriptor for this instance.Descriptor
is a singleton for every concreteDescribable
implementation, so ifa.getClass() == b.getClass()
then by defaulta.getDescriptor() == b.getDescriptor()
as well. (In rare cases a single implementation class may be used for instances with distinct descriptors.)- Specified by:
getDescriptor
in interfaceDescribable<J extends Item>
-
getSpec
public final String getSpec()
Gets the crontab specification. If you are not using cron service, just ignore it.
-
readResolve
protected Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
checkTriggers
public static void checkTriggers(Calendar cal)
-
all
public static DescriptorExtensionList<Trigger<?>,TriggerDescriptor> all()
Returns all the registeredTrigger
descriptors.
-
for_
public static List<TriggerDescriptor> for_(Item i)
Returns a subset ofTriggerDescriptor
s that applies to the given item.
-
-