Search in sources :

Example 1 with Jenkins

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

the class CachesTest method setup.

@Before
public void setup() {
    jenkins = mock(Jenkins.class);
    when(jenkins.getFullName()).thenReturn("");
    Folder folder = mock(Folder.class);
    when(folder.getParent()).thenReturn(jenkins);
    when(folder.getFullName()).thenReturn("/Repo");
    when(jenkins.getItem("/Repo")).thenReturn(folder);
    job = mock(Job.class);
    when(job.getParent()).thenReturn(folder);
    when(job.getFullName()).thenReturn("cool-branch");
    when(jenkins.getItemByFullName("/Repo/cool-branch", Job.class)).thenReturn(job);
}
Also used : Jenkins(jenkins.model.Jenkins) Folder(com.cloudbees.hudson.plugins.folder.Folder) Job(hudson.model.Job) Before(org.junit.Before)

Example 2 with Jenkins

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

the class SupportPlugin method threadDumpStartup.

@Initializer(after = InitMilestone.STARTED)
public static void threadDumpStartup() throws Exception {
    if (!logStartupPerformanceIssues)
        return;
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    final File f = new File(getRootDirectory(), "/startup-threadDump" + dateFormat.format(new Date()) + ".txt");
    if (!f.exists()) {
        try {
            f.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Thread t = new Thread("Support core plugin startup diagnostics") {

        @Override
        public void run() {
            while (true) {
                final Jenkins jenkins = Jenkins.getInstance();
                if (jenkins == null || jenkins.getInitLevel() != InitMilestone.COMPLETED) {
                    continue;
                }
                PrintStream ps = null;
                FileOutputStream fileOutputStream = null;
                try {
                    fileOutputStream = new FileOutputStream(f, true);
                    ps = new PrintStream(fileOutputStream, false, "UTF-8");
                    ps.println("=== Thread dump at " + new Date() + " ===");
                    ThreadDumps.threadDump(fileOutputStream);
                    // Generate a thread dump every few seconds/minutes
                    ps.flush();
                    Thread.sleep(TimeUnit.SECONDS.toMillis(secondsPerThreadDump));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    org.apache.commons.io.IOUtils.closeQuietly(ps);
                    org.apache.commons.io.IOUtils.closeQuietly(fileOutputStream);
                }
            }
        }
    };
    t.start();
}
Also used : Jenkins(jenkins.model.Jenkins) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) Initializer(hudson.init.Initializer)

Example 3 with Jenkins

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

the class ConfigFileComponent method addContents.

@Override
public void addContents(@NonNull Container container) {
    Jenkins jenkins = Jenkins.getInstance();
    File configFile = new File(jenkins.getRootDir(), "config.xml");
    if (configFile.exists()) {
        container.add(new XmlRedactedSecretFileContent("jenkins-root-configuration-files/" + configFile.getName(), configFile));
    } else {
        // this should never happen..
        LOGGER.log(Level.WARNING, "Jenkins global config file does not exist.");
    }
}
Also used : Jenkins(jenkins.model.Jenkins) File(java.io.File)

Example 4 with Jenkins

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

the class ProcFilesRetriever method addContents.

@Override
public void addContents(@NonNull Container container) {
    Jenkins j = Jenkins.getInstance();
    addUnixContents(container, j);
    for (Node node : j.getNodes()) {
        addUnixContents(container, node);
    }
}
Also used : Jenkins(jenkins.model.Jenkins) Node(hudson.model.Node)

Example 5 with Jenkins

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

the class RootCAs method addContents.

private void addContents(@NonNull Container container, @NonNull final Node node) {
    Computer c = node.toComputer();
    if (c == null) {
        return;
    }
    String name;
    if (node instanceof Jenkins) {
        name = "master";
    } else {
        name = "slave/" + node.getNodeName();
    }
    container.add(new Content("nodes/" + name + "/RootCA.txt") {

        @Override
        public void writeTo(OutputStream os) throws IOException {
            PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os, "utf-8")));
            try {
                out.println(getRootCA(node));
            } catch (IOException e) {
                SupportLogFormatter.printStackTrace(e, out);
            } finally {
                out.flush();
            }
        }
    });
}
Also used : Jenkins(jenkins.model.Jenkins) Content(com.cloudbees.jenkins.support.api.Content) OutputStream(java.io.OutputStream) Computer(hudson.model.Computer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

Jenkins (jenkins.model.Jenkins)70 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 File (java.io.File)7 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 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 FilePath (hudson.FilePath)4 Computer (hudson.model.Computer)4 Item (hudson.model.Item)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4