Title: [41193] trunk/hudson/plugins/vncrecorder/src/main: Saving disk space: configurable removing of videos of successful builds
Revision
41193
Author
tbaum
Date
2015-02-05 11:57:39 -0500 (Thu, 05 Feb 2015)

Log Message

Saving disk space: configurable removing of videos of successful builds

Modified Paths

Diff

Modified: trunk/hudson/plugins/vncrecorder/src/main/java/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper.java (41192 => 41193)


--- trunk/hudson/plugins/vncrecorder/src/main/java/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper.java	2014-11-18 09:20:24 UTC (rev 41192)
+++ trunk/hudson/plugins/vncrecorder/src/main/java/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper.java	2015-02-05 16:57:39 UTC (rev 41193)
@@ -28,6 +28,7 @@
 import hudson.Util;
 import hudson.model.BuildListener;
 import hudson.model.Item;
+import hudson.model.Result;
 import hudson.model.AbstractBuild;
 import hudson.model.AbstractProject;
 import hudson.model.Hudson;
@@ -62,13 +63,15 @@
 	private String vncServ;
 	private String vncPasswFilePath;
 	private Boolean setDisplay = false;
+	private Boolean removeIfSuccessful = false;
 
 	@DataBoundConstructor
-	public VncRecorderBuildWrapper(String vncServ, String vncPasswFilePath, Boolean setDisplay) 
+	public VncRecorderBuildWrapper(String vncServ, String vncPasswFilePath, Boolean setDisplay, Boolean removeIfSuccessful) 
 	{
 		this.vncServ = vncServ;
 		this.vncPasswFilePath = vncPasswFilePath;
 		this.setDisplay  = setDisplay;
+		this.removeIfSuccessful = removeIfSuccessful;
 	}
 
 
@@ -96,7 +99,16 @@
 		this.setDisplay = setDisplay;
 	}
 
+	public Boolean getRemoveIfSuccessful() {
+		return removeIfSuccessful;
+	}
 
+
+	public void setRemoveIfSuccessful(Boolean removeIfSuccessful) {
+		this.removeIfSuccessful = removeIfSuccessful;
+	}
+
+
 	@Override
 	public Environment setUp(@SuppressWarnings("rawtypes")AbstractBuild build, Launcher launcher,
 			final BuildListener listener) throws IOException, InterruptedException
@@ -119,7 +131,7 @@
 		}
 		
 		final VncRecorder vr = new VncRecorder();
-		Logger vncLogger = vr.getLoggerForPrintStream(listener.getLogger());
+		final Logger vncLogger = vr.getLoggerForPrintStream(listener.getLogger());
 		if (!launcher.isUnix())
 		{
 			listener.fatalError("Feature \"Record VNC session\" works only under Unix/Linux!");
@@ -173,12 +185,22 @@
 				final Date to = new Date();
 				recordState.cancel(true);
 				Thread.sleep(1000);
+				
+				if ((removeIfSuccessful && outFileSwf.exists()) && (build.getResult() == Result.SUCCESS || build.getResult() == null)  )
+				{
+					vncLogger.info("Build successful: Removing video file " + outFileSwf.getAbsolutePath() + " \n");
+					outFileSwf.delete();
+					outFileHtml.delete();
+					return true;
+				}
 
 				if (!outFileSwf.exists())
 				{
 					listener.error("File " + outFileSwf.getAbsolutePath() +" doesn't exist. \nFeature \"Record VNC session\" failed!");
 					return false;
 				}  
+				
+				
 				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd 'T' HH:mm:ss");
 				listener.hyperlink("artifact/" + outFileHtml.getName(),"Video from " + sf.format(from) + " to " + sf.format(to));
 				listener.getLogger().print("\n");

Modified: trunk/hudson/plugins/vncrecorder/src/main/resources/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper/config.jelly (41192 => 41193)


--- trunk/hudson/plugins/vncrecorder/src/main/resources/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper/config.jelly	2014-11-18 09:20:24 UTC (rev 41192)
+++ trunk/hudson/plugins/vncrecorder/src/main/resources/org/jenkinsci/plugins/vncrecorder/VncRecorderBuildWrapper/config.jelly	2015-02-05 16:57:39 UTC (rev 41193)
@@ -23,6 +23,11 @@
       <f:checkbox default="true"/>
       <label class="attach-previous">${%Set DISPLAY for this build on value of 'VNC server'}</label>
     </f:entry>
+    
+ <f:entry field="removeIfSuccessful">
+      <f:checkbox default="false"/>
+      <label class="attach-previous">${%Saving disk space: Remove videos of successful builds }</label>
+  </f:entry>    
 
 </j:jelly>
 

--
You received this message because you are subscribed to the Google Groups "Jenkins Commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-commits+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to