Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Jenkins 43491] Feature flag ".archive-jenkins-maven-event-spy-logs" …
…to archive the logs file generated by the Jenkins Maven Event Spy (#38) [JENKINS-43491] Feature flag ".archive-jenkins-maven-event-spy-logs" to archive the logs file generated by the Jenkins Maven Event Spy. Primarily intended for troubleshooting purpose. The ".archive-jenkins-maven-event-spy-logs" has to be created in the Jenkins build workspace.
- Loading branch information
Cyrille Le Clerc
committed
Apr 12, 2017
1 parent
3ba3588
commit eaf719e
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...java/org/jenkinsci/plugins/pipeline/maven/reporters/JenkinsMavenEventSpyLogsReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jenkinsci.plugins.pipeline.maven.reporters; | ||
|
||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import jenkins.model.ArtifactManager; | ||
import jenkins.util.BuildListenerAdapter; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Primarily for debugging purpose, archive the Maven build logs | ||
* | ||
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a> | ||
*/ | ||
public class JenkinsMavenEventSpyLogsReporter { | ||
public void process(@Nonnull StepContext context, @Nonnull FilePath mavenSpyLogs) throws IOException, InterruptedException { | ||
|
||
Run run = context.get(Run.class); | ||
ArtifactManager artifactManager = run.pickArtifactManager(); | ||
Launcher launcher = context.get(Launcher.class); | ||
TaskListener listener = context.get(TaskListener.class); | ||
FilePath workspace = context.get(FilePath.class); | ||
|
||
// ARCHIVE MAVEN BUILD LOGS | ||
FilePath tmpFile = new FilePath(workspace, "." + mavenSpyLogs.getName()); | ||
try { | ||
mavenSpyLogs.copyTo(tmpFile); | ||
listener.getLogger().println("[withMaven] archive " + mavenSpyLogs.getRemote() + " as " + mavenSpyLogs.getName()); | ||
// filePathInArchiveZone -> filePathInWorkspace | ||
Map<String, String> mavenBuildLogs = Collections.singletonMap(mavenSpyLogs.getName(), tmpFile.getName()); | ||
artifactManager.archive(workspace, launcher, new BuildListenerAdapter(listener), mavenBuildLogs); | ||
} catch (Exception e) { | ||
PrintWriter errorWriter = listener.error("[withMaven] WARNING Exception archiving Maven build logs " + mavenSpyLogs + ", skip file. "); | ||
e.printStackTrace(errorWriter); | ||
} finally { | ||
boolean deleted = tmpFile.delete(); | ||
if (!deleted) { | ||
listener.error("[withMaven] WARNING Failure to delete temporary file " + tmpFile); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters