Search in sources :

Example 71 with Jenkins

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

the class OtherLogs method addOtherControllerLogs.

/**
 * 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 addOtherControllerLogs(Container result) {
    Jenkins jenkins = Jenkins.getInstanceOrNull();
    if (jenkins != null) {
        GCLogs gcLogsComponents = Jenkins.lookup(GCLogs.class);
        String gcLogsFileLocation = gcLogsComponents == null ? null : gcLogsComponents.getGcLogFileLocation();
        FileFilter fileFilter;
        if (gcLogsFileLocation == null) {
            fileFilter = ROTATED_LOGFILE_FILTER;
        } else {
            try {
                // If GC logs are inside the Jenkins root directory, we need to filter them
                if (Files.isSameFile(new File(gcLogsFileLocation).getParentFile().toPath(), jenkins.getRootDir().toPath())) {
                    final Pattern gcLogFilesPattern = gcLogsComponents.isFileLocationParameterized(gcLogsFileLocation) || gcLogsComponents.isGcLogRotationConfigured() ? Pattern.compile("^" + new File(gcLogsFileLocation).getName().replaceAll("%[pt]", ".*") + ".*") : Pattern.compile("^" + new File(gcLogsFileLocation).getName() + "$");
                    fileFilter = pathname -> ROTATED_LOGFILE_FILTER.accept(pathname) && !gcLogFilesPattern.matcher(pathname.getName()).matches();
                } else {
                    fileFilter = ROTATED_LOGFILE_FILTER;
                }
            } catch (IOException e) {
                LOGGER.fine("[Support Bundle] Could not check if GC Logs file location '" + gcLogsFileLocation + "' is in Jenkins root directory");
                fileFilter = ROTATED_LOGFILE_FILTER;
            }
        }
        File[] files = jenkins.getRootDir().listFiles(fileFilter);
        if (files != null) {
            for (File f : files) {
                result.add(new FileContent("other-logs/{0}", new String[] { f.getName() }, f));
            }
        }
    }
}
Also used : Jenkins(jenkins.model.Jenkins) FileContent(com.cloudbees.jenkins.support.api.FileContent) Pattern(java.util.regex.Pattern) IOException(java.io.IOException) FileFilter(java.io.FileFilter) File(java.io.File)

Example 72 with Jenkins

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

the class RootCAs method addContents.

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

Example 73 with Jenkins

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

the class TaskLogs method addControllerTasksLogs.

/**
 * Grabs any files that look like log files directly under <code>$JENKINS_HOME/logs</code>, 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 addControllerTasksLogs(Container result) {
    Jenkins jenkins = Jenkins.getInstanceOrNull();
    if (jenkins != null) {
        File logsRoot = getLogsRoot();
        for (File logs : new File[] { logsRoot, new File(logsRoot, "tasks") }) {
            File[] files = logs.listFiles(ROTATED_LOGFILE_FILTER);
            if (files != null) {
                Arrays.sort(files);
                long recently = System.currentTimeMillis() - FileListCapComponent.MAX_LOG_FILE_AGE_MS;
                for (File f : files) {
                    if (f.lastModified() > recently) {
                        result.add(new FileContent("task-logs/{0}", new String[] { 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