Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Last active February 21, 2019 00:21
Show Gist options
  • Save marcosborges/0311da37619b10f8e9a20dafd45812db to your computer and use it in GitHub Desktop.
Save marcosborges/0311da37619b10f8e9a20dafd45812db to your computer and use it in GitHub Desktop.
def _jenkins = Jenkins.getActiveInstance();
def _store = _jenkins.getExtensionList(
org.jenkinsci.plugins.configfiles.GlobalConfigFiles.class
).get(
org.jenkinsci.plugins.configfiles.GlobalConfigFiles.class
);
println "CONFIGURAÇÕES GLOBAIS"
def _configs = _store.getConfigs()
for(c in _configs){
println " ${c.id}: ${c.name}"
}
println "CONFIGURAÇÕES NAS PASTAS"
def folders = _jenkins.getAllItems(
com.cloudbees.hudson.plugins.folder.Folder.class
)
for(f in folders){
println "FOLDER: ${f.name}"
def _folderStore = f.getAction(org.jenkinsci.plugins.configfiles.folder.FolderConfigFileAction.class).getStore();
def _foldersConfigs = _folderStore.getConfigs()
for(c in _foldersConfigs){
println " ${c.id}: ${c.name}"
}
println "Cadastrando configuração na pasta ${f.name}"
_folderStore.save(
new org.jenkinsci.plugins.configfiles.custom.CustomConfig(
"${f.name}1", "${f.name}2", "comment", "content"
)
);
}
//Cadastrar nova configuração
_store.save(
new org.jenkinsci.plugins.configfiles.custom.CustomConfig(
"NOVACFG", "NOVACFG", "comment", "content"
)
);
def _jenkins = Jenkins.getActiveInstance();
def _store = _jenkins.getExtensionList(
org.jenkinsci.plugins.configfiles.GlobalConfigFiles.class
).get(
org.jenkinsci.plugins.configfiles.GlobalConfigFiles.class
);
def dir = "./templates"
def files = new File(dir)
files.eachFileRecurse (groovy.io.FileType.FILES) { file ->
println file.path
def name = file.path.replace(dir,'')
_store.save(
new org.jenkinsci.plugins.configfiles.custom.CustomConfig(
"${name}",
"${name}",
"${name.replace('/',' ')}",
new File("${file.path}").getText('UTF-8')
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment