use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.
the class ActiveDirectoryTest method configure_active_directory.
@Test
@ConfiguredWithCode(value = "ActiveDirectoryTest.yml")
public void configure_active_directory() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final ActiveDirectorySecurityRealm realm = (ActiveDirectorySecurityRealm) jenkins.getSecurityRealm();
assertEquals(1, realm.domains.size());
final ActiveDirectoryDomain domain = realm.domains.get(0);
assertEquals("acme", domain.name);
assertEquals("admin", domain.bindName);
assertEquals("ADMIN123", domain.bindPassword.getPlainText());
assertEquals("ad1.acme.com:123,ad2.acme.com:456", domain.servers);
assertTrue(realm.removeIrrelevantGroups);
assertTrue(realm.startTls);
}
use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.
the class AgentProtocolsTest method configure_agent_protocols.
@Test
@ConfiguredWithCode(value = "AgentProtocolsTest.yml")
public void configure_agent_protocols() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Set<String> agentProtocols = Arrays.stream(new String[] { "JNLP4-connect", "Ping" }).collect(Collectors.toSet());
assertEquals(agentProtocols, jenkins.getAgentProtocols());
}
use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.
the class Configurator method lookup.
/**
* Looks for a configurator for exact type.
* @param type Type
* @return Configurator or {@code null} if it is not found
*/
@CheckForNull
public static Configurator lookup(Type type) {
Class clazz = Types.erasure(type);
final Jenkins jenkins = Jenkins.getInstance();
final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
for (Configurator c : l) {
if (clazz == c.getTarget()) {
// this type has a dedicated Configurator implementation
return c;
}
}
if (Collection.class.isAssignableFrom(clazz)) {
// TODO: Only try to cast if we can actually get the parameterized type
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
Type actualType = pt.getActualTypeArguments()[0];
if (actualType instanceof WildcardType) {
actualType = ((WildcardType) actualType).getUpperBounds()[0];
}
if (!(actualType instanceof Class)) {
throw new IllegalStateException("Can't handle " + type);
}
return lookup(actualType);
}
}
if (Descriptor.class.isAssignableFrom(clazz)) {
return new DescriptorConfigurator((Descriptor) jenkins.getExtensionList(clazz).get(0));
}
if (getDataBoundConstructor(clazz) != null) {
return new DataBoundConfigurator(clazz);
}
if (Modifier.isAbstract(clazz.getModifiers()) && Describable.class.isAssignableFrom(clazz)) {
// this is a jenkins Describable component, with various implementations
return new HeteroDescribableConfigurator(clazz);
}
if (TopLevelItem.class.isAssignableFrom(clazz)) {
return new TopLevelItemConfigurator(clazz);
}
if (Extension.class.isAssignableFrom(clazz)) {
return new ExtensionConfigurator(clazz);
}
if (Stapler.lookupConverter(clazz) != null) {
return new PrimitiveConfigurator(clazz);
}
logger.warning("Configuration-as-Code can't handle type " + type);
return null;
}
use of jenkins.model.Jenkins 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;
}
use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.
the class SeedJobTest method configure_seed_job.
@Test
@ConfiguredWithCode("SeedJobTest.yml")
public void configure_seed_job() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final TopLevelItem test = jenkins.getItem("configuration-as-code");
assertNotNull(test);
assertTrue(test instanceof WorkflowMultiBranchProject);
}
Aggregations