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));
}
}
}
}
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);
}
}
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));
}
}
}
}
}
}
Aggregations