Search in sources :

Example 6 with Jenkins

use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method testDurableAgainstCleanRestartSurvivesIt.

/**
 * Verifies that if we're only durable against clean restarts, the pipeline will survive it.
 */
@Test
public void testDurableAgainstCleanRestartSurvivesIt() throws Exception {
    final String jobName = "durableAgainstClean";
    final String[] logStart = new String[1];
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            Jenkins jenkins = story.j.jenkins;
            WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
            FlowExecution exec = run.getExecution();
            assertBaseStorageType(exec, BulkFlowNodeStorage.class);
            logStart[0] = JenkinsRule.getLog(run);
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
            Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint());
            assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class);
            verifySafelyResumed(story.j, run, true, logStart[0]);
        }
    });
}
Also used : Jenkins(jenkins.model.Jenkins) Statement(org.junit.runners.model.Statement) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BulkFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.BulkFlowNodeStorage) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 7 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class Configurator method lookupForBaseType.

/**
 * Finds a Configurator for base type and a short name
 * @param clazz Base class
 * @param shortname Short name of the implementation
 * @return Configurator
 */
@CheckForNull
public static Configurator lookupForBaseType(Class<?> clazz, @Nonnull String shortname) {
    final Jenkins jenkins = Jenkins.getInstance();
    final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
    for (Configurator c : l) {
        if (shortname.equalsIgnoreCase(c.getName())) {
            // short name match, ensure that the type is compliant
            if (clazz.isAssignableFrom(c.getTarget())) {
                // Implements child class
                return c;
            }
        }
    }
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) CheckForNull(javax.annotation.CheckForNull)

Example 8 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfigurator method configure.

@Override
public Jenkins configure(Object c) throws Exception {
    Map config = (Map) c;
    Jenkins jenkins = Jenkins.getInstance();
    configure(config, jenkins);
    return jenkins;
}
Also used : Jenkins(jenkins.model.Jenkins) Map(java.util.Map)

Example 9 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class AdminWhitelistRuleConfiguratorTest method checkM2SSecurityKillSwitch_enabled.

@Test
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Slave2MasterSecurityKillSwitch_enabled.yml")
public void checkM2SSecurityKillSwitch_enabled() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
    Assert.assertTrue("MasterToSlave Security should be enabled", rule.getMasterKillSwitch());
}
Also used : Jenkins(jenkins.model.Jenkins) AdminWhitelistRule(jenkins.security.s2m.AdminWhitelistRule) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 10 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class HudsonPrivateSecurityRealmConfiguratorTest method configure_local_security_and_admin_user.

@Test
@ConfiguredWithCode("HudsonPrivateSecurityRealmConfiguratorTest.yml")
public void configure_local_security_and_admin_user() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    final HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm) jenkins.getSecurityRealm();
    assertFalse(securityRealm.allowsSignup());
    final User admin = User.getById("admin", false);
    assertNotNull(admin);
    final HudsonPrivateSecurityRealm.Details details = admin.getProperty(HudsonPrivateSecurityRealm.Details.class);
    assertTrue(details.isPasswordCorrect("1234"));
    final FullControlOnceLoggedInAuthorizationStrategy authorizationStrategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
    assertTrue(authorizationStrategy.isAllowAnonymousRead());
}
Also used : Jenkins(jenkins.model.Jenkins) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) User(hudson.model.User) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Aggregations

Jenkins (jenkins.model.Jenkins)73 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 File (java.io.File)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 Statement (org.junit.runners.model.Statement)7 CheckForNull (javax.annotation.CheckForNull)6 FilePath (hudson.FilePath)5 Computer (hudson.model.Computer)5 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 Item (hudson.model.Item)4 Node (hudson.model.Node)4 Date (java.util.Date)4