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
Triggerfrom a plugin, putExtensionon yourTriggerDescriptorclass.- Author:
- Kohsuke Kawaguchi
- See Also:
TriggeredItem
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTrigger.CronRuns every minute to checkTimerTriggerand schedules build.-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
Fields Modifier and Type Field Description static longCRON_THRESHOLDUsed to be milliseconds, now is seconds since Jenkins 2.289.protected Jjobprotected Stringspecprotected CronTabListtabsstatic TimertimerDeprecated.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 registeredTriggerdescriptors.static voidcheckTriggers(Calendar cal)static List<TriggerDescriptor>for_(Item i)Returns a subset ofTriggerDescriptors that applies to the given item.TriggerDescriptorgetDescriptor()Gets the descriptor for this instance.ActiongetProjectAction()Deprecated.as of 1.341 UsegetProjectActions()instead.Collection<? extends Action>getProjectActions()Actions to be displayed in the job page.StringgetSpec()Gets the crontab specification.protected ObjectreadResolve()voidrun()Executes the triggered task.voidstart(J project, boolean newInstance)Called when aTriggeris loaded into memory and started.voidstop()Called before aTriggeris removed.StringtoString()
-
-
-
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 newTriggerthat getsrunperiodically. 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 newTriggerwithout using cron.
-
-
Method Detail
-
start
public void start(J project, boolean newInstance)
Called when aTriggeris 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 aProjectloaded 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()
Actions 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:DescribableGets the descriptor for this instance.Descriptoris a singleton for every concreteDescribableimplementation, 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:
getDescriptorin 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 registeredTriggerdescriptors.
-
for_
public static List<TriggerDescriptor> for_(Item i)
Returns a subset ofTriggerDescriptors that applies to the given item.
-
-