Search in sources :

Example 46 with Jenkins

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

the class LDAPSecurityRealmTest method configure_securityRealm.

@Test
@ConfiguredWithCode("LDAPSecurityRealmTest.yml")
public void configure_securityRealm() {
    final Jenkins jenkins = Jenkins.getInstance();
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
    assertTrue(securityRealm.getUserIdStrategy() instanceof IdStrategy.CaseInsensitive);
    assertTrue(securityRealm.getGroupIdStrategy() instanceof IdStrategy.CaseSensitive);
    final LDAPConfiguration configuration = securityRealm.getConfigurations().get(0);
    assertEquals("ldap.acme.com", configuration.getServer());
    assertEquals("SECRET", configuration.getManagerPassword());
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) IdStrategy(jenkins.model.IdStrategy) LDAPConfiguration(jenkins.security.plugins.ldap.LDAPConfiguration) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 47 with Jenkins

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

the class MailerTest method configure_mailer.

@Test
@ConfiguredWithCode("MailerTest.yml")
public void configure_mailer() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
    assertEquals("4441", descriptor.getSmtpPort());
    assertEquals("do-not-reply@acme.org", descriptor.getReplyToAddress());
    // FIXME setAdminAddress is deprecated and should NOT be set this way
    // see https://github.com/jenkinsci/mailer-plugin/pull/39
    assertEquals("admin@acme.org", descriptor.getAdminAddress());
}
Also used : Jenkins(jenkins.model.Jenkins) Mailer(hudson.tasks.Mailer) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 48 with Jenkins

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

the class RootElementConfigurator method all.

static List<RootElementConfigurator> all() {
    List<RootElementConfigurator> configurators = new ArrayList<>();
    final Jenkins jenkins = Jenkins.getInstance();
    configurators.addAll(jenkins.getExtensionList(RootElementConfigurator.class));
    for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
        configurators.add(new GlobalConfigurationCategoryConfigurator(category));
    }
    return configurators;
}
Also used : Jenkins(jenkins.model.Jenkins) ArrayList(java.util.ArrayList) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory)

Example 49 with Jenkins

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

the class WorkflowRun method sleep.

private AsynchronousExecution sleep() {
    final AsynchronousExecution asynchronousExecution = new AsynchronousExecution() {

        @Override
        public void interrupt(boolean forShutdown) {
            if (forShutdown) {
                return;
            }
            Timer.get().submit(new Runnable() {

                @Override
                public void run() {
                    if (execution == null) {
                        return;
                    }
                    Executor executor = getExecutor();
                    if (executor == null) {
                        LOGGER.log(Level.WARNING, "Lost executor for {0}", WorkflowRun.this);
                        return;
                    }
                    try {
                        Collection<CauseOfInterruption> causes = executor.getCausesOfInterruption();
                        execution.interrupt(executor.abortResult(), causes.toArray(new CauseOfInterruption[causes.size()]));
                    } catch (Exception x) {
                        LOGGER.log(Level.WARNING, null, x);
                    }
                    executor.recordCauseOfInterruption(WorkflowRun.this, listener);
                    printLater(StopState.TERM, "Click here to forcibly terminate running steps");
                }
            });
        }

        @Override
        public boolean blocksRestart() {
            return execution != null && execution.blocksRestart();
        }

        @Override
        public boolean displayCell() {
            return blocksRestart();
        }
    };
    final AtomicReference<ScheduledFuture<?>> copyLogsTask = new AtomicReference<>();
    copyLogsTask.set(copyLogsExecutorService().scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            synchronized (completed) {
                if (completed.get()) {
                    asynchronousExecution.completed(null);
                    copyLogsTask.get().cancel(false);
                    return;
                }
                Jenkins jenkins = Jenkins.getInstance();
                if (jenkins == null || jenkins.isTerminating()) {
                    LOGGER.log(Level.FINE, "shutting down, breaking waitForCompletion on {0}", this);
                    // Stop writing content, in case a new set of objects gets loaded after in-VM restart and starts writing to the same file:
                    listener.closeQuietly();
                    listener = new StreamBuildListener(new NullStream());
                    return;
                }
                try (WithThreadName naming = new WithThreadName(" (" + WorkflowRun.this + ")")) {
                    copyLogs();
                }
            }
        }
    }, 1, 1, TimeUnit.SECONDS));
    return asynchronousExecution;
}
Also used : AsynchronousExecution(jenkins.model.queue.AsynchronousExecution) NullStream(hudson.util.NullStream) WithThreadName(org.jenkinsci.plugins.workflow.support.concurrent.WithThreadName) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamBuildListener(hudson.model.StreamBuildListener) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) ScheduledFuture(java.util.concurrent.ScheduledFuture) Jenkins(jenkins.model.Jenkins) Executor(hudson.model.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collection(java.util.Collection)

Example 50 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class JenkinsLogs method addOtherMasterLogs.

/**
 * Grabs any files that look like log files directly under {@code $JENKINS_HOME}, just in case
 * any of them are useful.
 * Does not add anything if Jenkins instance is unavailable.
 * Some plugins write log files here.
 */
private void addOtherMasterLogs(Container result) {
    final Jenkins jenkins = Jenkins.getInstance();
    File[] files = jenkins.getRootDir().listFiles(ROTATED_LOGFILE_FILTER);
    if (files != null) {
        for (File f : files) {
            result.add(new FileContent("other-logs/" + f.getName(), f));
        }
    }
    File logs = getLogsRoot();
    files = logs.listFiles(ROTATED_LOGFILE_FILTER);
    if (files != null) {
        for (File f : files) {
            result.add(new FileContent("other-logs/" + f.getName(), f));
        }
    }
    File taskLogs = new File(logs, "tasks");
    files = taskLogs.listFiles(ROTATED_LOGFILE_FILTER);
    if (files != null) {
        for (File f : files) {
            result.add(new FileContent("other-logs/" + f.getName(), f));
        }
    }
}
Also used : Jenkins(jenkins.model.Jenkins) FileContent(com.cloudbees.jenkins.support.api.FileContent) File(java.io.File)

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