Search in sources :

Example 1 with JenkinsJobManagement

use of javaposse.jobdsl.plugin.JenkinsJobManagement in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfigurator method describe.

@Override
public Set<Attribute> describe() {
    final Set<Attribute> attributes = super.describe();
    final Jenkins jenkins = Jenkins.getInstance();
    attributes.add(new PersistedListAttribute<Cloud>("clouds", jenkins.clouds, Cloud.class));
    attributes.add(new Attribute<String>("jobs", String.class).multiple(true).setter((target, attribute, value) -> {
        JenkinsJobManagement mng = new JenkinsJobManagement(System.out, new EnvVars(), null, null, LookupStrategy.JENKINS_ROOT);
        for (String script : (List<String>) value) {
            new JenkinsDslScriptLoader(mng).runScript(script);
        }
    }));
    // Check for unclassified Descriptors
    final ExtensionList<Descriptor> descriptors = jenkins.getExtensionList(Descriptor.class);
    for (Descriptor descriptor : descriptors) {
        if (descriptor.getGlobalConfigPage() != null && descriptor.getCategory() instanceof GlobalConfigurationCategory.Unclassified) {
            final DescriptorConfigurator configurator = new DescriptorConfigurator(descriptor);
            attributes.add(new Attribute(configurator.getName(), configurator.getTarget()).setter(NOOP));
        }
    }
    // Add remoting security, all legwork will be done by a configurator
    attributes.add(new Attribute("remotingSecurity", AdminWhitelistRule.class).setter(NOOP));
    return attributes;
}
Also used : JenkinsDslScriptLoader(javaposse.jobdsl.plugin.JenkinsDslScriptLoader) JenkinsJobManagement(javaposse.jobdsl.plugin.JenkinsJobManagement) Descriptor(hudson.model.Descriptor) Jenkins(jenkins.model.Jenkins) AdminWhitelistRule(jenkins.security.s2m.AdminWhitelistRule) Set(java.util.Set) Logger(java.util.logging.Logger) Level(java.util.logging.Level) List(java.util.List) Map(java.util.Map) Extension(hudson.Extension) LookupStrategy(javaposse.jobdsl.plugin.LookupStrategy) EnvVars(hudson.EnvVars) Cloud(hudson.slaves.Cloud) ExtensionList(hudson.ExtensionList) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory) JenkinsJobManagement(javaposse.jobdsl.plugin.JenkinsJobManagement) JenkinsDslScriptLoader(javaposse.jobdsl.plugin.JenkinsDslScriptLoader) Jenkins(jenkins.model.Jenkins) EnvVars(hudson.EnvVars) Cloud(hudson.slaves.Cloud) Descriptor(hudson.model.Descriptor) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory)

Aggregations

EnvVars (hudson.EnvVars)1 Extension (hudson.Extension)1 ExtensionList (hudson.ExtensionList)1 Descriptor (hudson.model.Descriptor)1 Cloud (hudson.slaves.Cloud)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 JenkinsDslScriptLoader (javaposse.jobdsl.plugin.JenkinsDslScriptLoader)1 JenkinsJobManagement (javaposse.jobdsl.plugin.JenkinsJobManagement)1 LookupStrategy (javaposse.jobdsl.plugin.LookupStrategy)1 GlobalConfigurationCategory (jenkins.model.GlobalConfigurationCategory)1 Jenkins (jenkins.model.Jenkins)1 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)1