Class ItemListener

java.lang.Object
hudson.model.listeners.ItemListener
All Implemented Interfaces:
ExtensionPoint
Direct Known Subclasses:
ArtifactArchiver.Migrator, BuildTrigger.DescriptorImpl.ItemListenerImpl, DisplayNameListener, Fingerprint.ProjectRenameListener, Job.LastItemListener, Job.SubItemBuildsLocationImpl, LazyBuildMixIn.ItemListenerImpl, ListView.Listener, ReverseBuildTrigger.ItemListenerImpl

public class ItemListener extends Object implements ExtensionPoint
Receives notifications about CRUD operations of Item.
Since:
1.74
Author:
Kohsuke Kawaguchi
  • Constructor Details

    • ItemListener

      public ItemListener()
  • Method Details

    • onCreated

      public void onCreated(Item item)
      Called after a new job is created and added to Jenkins, before the initial configuration page is provided.

      This is useful for changing the default initial configuration of newly created jobs. For example, you can enable/add builders, etc.

    • onCheckCopy

      public void onCheckCopy(Item src, ItemGroup parent) throws Failure
      Called before a job is copied into a new parent, providing the ability to veto the copy operation before it starts.
      Parameters:
      src - the item being copied
      parent - the proposed parent
      Throws:
      Failure - to veto the operation.
      Since:
      2.51
    • onCopied

      public void onCopied(Item src, Item item)
      Called after a new job is created by copying from an existing job. For backward compatibility, the default implementation of this method calls onCreated(Item). If you choose to handle this method, think about whether you want to call super.onCopied or not.
      Parameters:
      src - The source item that the new one was copied from. Never null.
      item - The newly created item. Never null.
      Since:
      1.325 Before this version, a copy triggered onCreated(Item).
    • onLoaded

      public void onLoaded()
      Called after all the jobs are loaded from disk into Jenkins object.
    • onCheckDelete

      public void onCheckDelete(Item item) throws Failure, InterruptedException
      Called before an item is deleted, providing the ability to veto the deletion operation before it starts.
      Parameters:
      item - the item being deleted
      Throws:
      Failure - to veto the operation.
      InterruptedException - If a blocking condition was interrupted, also vetoing the operation.
      Since:
      2.470
    • onDeleted

      public void onDeleted(Item item)
      Called right before a job is going to be deleted. At this point the data files of the job is already gone.
    • onRenamed

      public void onRenamed(Item item, String oldName, String newName)
      Called after a job is renamed. Most implementers should rather use onLocationChanged(hudson.model.Item, java.lang.String, java.lang.String).
      Parameters:
      item - The job being renamed.
      oldName - The old name of the job.
      newName - The new name of the job. Same as Item.getName().
      Since:
      1.146
    • onLocationChanged

      public void onLocationChanged(Item item, String oldFullName, String newFullName)
      Called after an item’s fully-qualified location has changed. This might be because:
      • This item was renamed.
      • Some ancestor folder was renamed.
      • This item was moved between folders (or from a folder to Jenkins root or vice-versa).
      • Some ancestor folder was moved.
      Where applicable, onRenamed(hudson.model.Item, java.lang.String, java.lang.String) will already have been called on this item or an ancestor. And where applicable, onLocationChanged(hudson.model.Item, java.lang.String, java.lang.String) will already have been called on its ancestors.

      This method should be used (instead of onRenamed(hudson.model.Item, java.lang.String, java.lang.String)) by any code which seeks to keep (absolute) references to items up to date: if a persisted reference matches oldFullName, replace it with newFullName.

      Parameters:
      item - an item whose absolute position is now different
      oldFullName - the former Item.getFullName()
      newFullName - the current Item.getFullName()
      Since:
      1.548
      See Also:
    • onUpdated

      public void onUpdated(Item item)
      Called after a job has its configuration updated.
      Since:
      1.460
    • onBeforeShutdown

      public void onBeforeShutdown()
      Since:
      1.446 Called at the beginning of the orderly shutdown sequence to allow plugins to clean up stuff
    • register

      @Deprecated public void register()
      Deprecated.
      as of 1.286 put Extension on your class to have it auto-registered.
      Registers this instance to Hudson and start getting notifications.
    • all

      public static ExtensionList<ItemListener> all()
      All the registered ItemListeners.
    • fireOnCopied

      public static void fireOnCopied(Item src, Item result)
    • checkBeforeCopy

      public static void checkBeforeCopy(Item src, ItemGroup parent) throws Failure
      Call before a job is copied into a new parent, to allow the ItemListener implementations the ability to veto the copy operation before it starts.
      Parameters:
      src - the item being copied
      parent - the proposed parent
      Throws:
      Failure - if the copy operation has been vetoed.
      Since:
      2.51
    • fireOnCreated

      public static void fireOnCreated(Item item)
    • fireOnUpdated

      public static void fireOnUpdated(Item item)
    • checkBeforeDelete

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void checkBeforeDelete(Item item) throws Failure, InterruptedException
      Throws:
      Failure
      InterruptedException
    • fireOnDeleted

      public static void fireOnDeleted(Item item)
      Since:
      1.548
    • fireLocationChange

      public static void fireLocationChange(Item rootItem, String oldFullName)
      Parameters:
      rootItem - the topmost item whose location has just changed
      oldFullName - the previous Item.getFullName()
      Since:
      1.548