Skip to content

print out build container logs when verbose is enabled #52

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -367,4 +367,17 @@ private List<String> dockerCommandArgs() {
}
return args;
}

public void logs(String container) throws IOException, InterruptedException {
ArgumentListBuilder args = dockerCommand()
.add("logs", "-t", container);

listener.getLogger().println("Retrieving container logs");
OutputStream out = listener.getLogger();
OutputStream err = listener.getLogger();
int status = launcher.launch()
.cmds(args)
.stdout(out).stderr(err).quiet(true).join();
if (status != 0) listener.error("Unable to retrieve logs from container");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,16 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
return new Environment() {
@Override
public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
return build.getAction(BuiltInContainer.class).tearDown();
BuiltInContainer builtIn = build.getAction(BuiltInContainer.class);
if ( verbose ) {
try {
builtIn.getDocker().logs(builtIn.container);
}
catch ( Exception ex ) {
LOGGER.log(Level.WARNING, "Error getting container logs", ex);
}
}
return builtIn.tearDown();
}
};
}
Expand Down