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 folder-scoped, it checks that the current job is located within the configured folder path.

      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 the current job is not within the allowed folder scope