Class ConfigFileSource

All Implemented Interfaces:
ExtensionPoint, Describable<JsonSource>, Serializable

public class ConfigFileSource extends JsonSource
A JsonSource implementation that loads JSON content from a Jenkins Config File, either globally scoped or folder-scoped.

When folder-scoped, the parameter is only available to jobs located within the specified folder or its subfolders.

This class supports validation to prevent unauthorized access to configuration files outside the designated folder path.

Author:
Caner Yanbaz
See Also:
  • Constructor Details

    • ConfigFileSource

      @DataBoundConstructor public ConfigFileSource(boolean folderScoped, String folderPath, String configId)
      Constructs a new ConfigFileSource instance.
      Parameters:
      folderScoped - whether the config file is folder-scoped
      folderPath - the full Jenkins path of the folder (only relevant if folderScoped is true)
      configId - the ID of the config file as defined in the Config File Provider plugin
  • Method Details

    • isFolderScoped

      public boolean isFolderScoped()
    • getFolderPath

      public String getFolderPath()
    • getConfigId

      public String getConfigId()
    • loadJson

      public String loadJson()
      Loads the JSON content from the configured Jenkins config file.

      If folderScoped is true, the method resolves the folder using the configured path, ensures the current job is inside that folder, and retrieves the corresponding config. If folderScoped is false, it attempts to resolve the config globally.

      Specified by:
      loadJson in class JsonSource
      Returns:
      the raw JSON content as a string
      Throws:
      IllegalArgumentException - if the config file is not found or not accessible
      IllegalStateException - if folder-scoped access fails (e.g. folder mismatch or missing permission)