Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-54678] Add symlink to compressed log #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.kohsuke.stapler.StaplerRequest;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -61,12 +64,12 @@ public final static class CompressBuildlogRunListener extends RunListener<Run> {

private static boolean hasBuildCompressorConfigured(Run<?, ?> run) {
Job<?, ?> parent = run.getParent();

// Check project for BuildCompressor configuration
if (parent.getProperty(BuildLogCompressor.class) != null) {
return true;
}

// Multi-configuration runs have an extra parent to get to the project. Check that too.
if (parent.getParent() instanceof Job) {
Job<?, ?> grandParent = (Job<?, ?>)parent.getParent();
Expand All @@ -79,7 +82,7 @@ private static boolean hasBuildCompressorConfigured(Run<?, ?> run) {
// No configuration to be found!
return false;
}

@Override
public void onFinalized(Run run) {
File log = run.getLogFile();
Expand Down Expand Up @@ -128,6 +131,19 @@ public void onFinalized(Run run) {
// XXX try multiple times because Windows?
if (!log.delete()) {
LOGGER.log(Level.WARNING, String.format("Failed to delete build log of %s after compression", run));
return;
}

// Create symlink log -> log.gz
Path target = Paths.get(gzippedLogName);
Path symlink = Paths.get(log.getPath());
try {
Files.createSymbolicLink(symlink, target);
} catch (IOException e) {
LOGGER.log(Level.WARNING, String.format("Failed to create symlink %s for %s", gzippedLogName, run));
} catch (UnsupportedOperationException e) {
// Some file systems do not support symbolic links.
LOGGER.log(Level.WARNING, String.format("Failed to create symlink %s for %s as it is unsupported", gzippedLogName, run));
}
}
}
Expand Down