Class ConfigFiles

java.lang.Object
org.jenkinsci.plugins.configfiles.ConfigFiles

public class ConfigFiles extends Object
Central class to access configuration files
  • Method Details

    • getConfigsInContext

      @NonNull public static List<Config> getConfigsInContext(@Nullable ItemGroup itemGroup, Class<? extends Descriptor> descriptor)
      Lists all configurations of the given type which are visible in the context of the provided item group. e.g. if itemGroup is of type AbstractFolder or within an AbstractFolder, then this method will list all configurations in that folder and in all parent folders up (and including) all configurations on jenkins top level.

      This method is typically used to display all available options in the UI.

      Parameters:
      itemGroup - the context
      descriptor - configuration type
      Returns:
      a list of configuration items of the requested type, visible in the provided context.
    • getByIdOrNull

      public static <T extends Config> T getByIdOrNull(@Nullable ItemGroup itemGroup, @NonNull String configId)
      Used to get hold on a single configuration in the given context. The configuration will be looked up for from the current context (itemGroup, e.g. AbstractFolder or Jenkins if not within a folder) until a configuration with the given id was found.
      Type Parameters:
      T - expected type of the returned configuration item.
      Parameters:
      itemGroup - context to start the lookup from
      configId - id of the configuration to search for
      Returns:
      null if no configuration was found
      Throws:
      IllegalArgumentException - if while walking up the tree, one of the parents is not either of type AbstractFolder, Item or Jenkins
    • getByIdOrNull

      public static <T extends Config> T getByIdOrNull(@NonNull Item item, @NonNull String configId)
      Used to get hold on a single configuration in the given context. The configuration will be looked up for from the current context (item, e.g. AbstractFolder or Jenkins if not within a folder) until a configuration with the given id was found.
      Type Parameters:
      T - expected type of the returned configuration item.
      Parameters:
      item - context to start the lookup from
      configId - id of the configuration to search for
      Returns:
      null if no configuration was found
      Throws:
      IllegalArgumentException - if while walking up the tree, one of the parents is not either of type AbstractFolder, Item or Jenkins
    • getByIdOrNull

      public static <T extends Config> T getByIdOrNull(@NonNull Run<?,?> build, @NonNull String configId)
      Used to get hold on a single configuration in the given context. The configuration will be looked up for from the current context (itemGroup, e.g. AbstractFolder or Jenkins if not within a folder) until a configuration with the given id was found.

      Usually used to access the configuration during a run/job execution.

      Type Parameters:
      T - expected type of the returned configuration item.
      Parameters:
      build - active to start the lookup from
      configId - id of the configuration to search for
      Returns:
      null if no configuration was found
      Throws:
      IllegalArgumentException - if while walking up the tree, one of the parents is not either of type AbstractFolder, Item or Jenkins