Issue
I have stored configurations for some jobs in JSON format in the managed file section of Jenkins and it works as expected. I want to expand this by changing these jobs to paralyzed one, where all available managed files (not the global ones) could be selected from a combo box, but I have problems getting all available managed files. Plugins like the configFileProvider are capable to get both the global ones and more workspace/namespace specific ones, so I thought there would be an easy way to achieve this.
Adding a more job-specific not global config file
def files = org.jenkinsci.plugins.configfiles.GlobalConfigFiles.get().getConfigs()
works fine for the global ones, but I want to get workspace/namespace specific ones and thought it would go something like this
def files = org.jenkinsci.plugins.configfiles.getConfigsInContext()
It would be amazing if somebody could point me in the right direction how to achieve this.
Thanks
Solution
Check the following script
// name of the folde you want get configfiles from
def folderName = "Folder2"
def folderItem = Jenkins.instance.getAllItems(com.cloudbees.hudson.plugins.folder.AbstractFolder.class).find{ (it.name == folderName) }
// If you want to filter a specific configFile type, example Json configs here
def descriptor = org.jenkinsci.plugins.configfiles.json.JsonConfig.JsonConfigProvider.class
def allConfigFiles = folderItem.getProperties().get(org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty.class).getConfigs();
def jonConfigFiles = folderItem.getProperties().get(org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty.class).getConfigs(descriptor);
echo "$allConfigFiles"
echo "$jonConfigFiles"
Answered By - ycr
Answer Checked By - Marie Seifert (JavaFixing Admin)