-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
668625d
commit f394b1b
Showing
7 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...epanik/jenkins/buildhistorymanager/descriptors/actions/DeleteLogFileActionDescriptor.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,24 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.Action; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.DeleteLogFileAction; | ||
|
||
/** | ||
* Descriptor implementation needed to render UI for {@link DeleteLogFileAction}. | ||
* | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
@Extension | ||
public class DeleteLogFileActionDescriptor extends Descriptor<Action> { | ||
|
||
public DeleteLogFileActionDescriptor() { | ||
super(DeleteLogFileAction.class); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Delete log file"; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...va/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteLogFileAction.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,37 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.model.actions; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import hudson.model.Run; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* Deletes the build log file. | ||
* | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
* @see Run#delete() | ||
*/ | ||
public class DeleteLogFileAction extends Action { | ||
|
||
private static final Logger LOG = Logger.getLogger(DeleteLogFileAction.class.getName()); | ||
|
||
@DataBoundConstructor | ||
public DeleteLogFileAction() { | ||
// Jenkins stapler requires to have public constructor with @DataBoundConstructor | ||
} | ||
|
||
@Override | ||
public void perform(Run<?, ?> run) throws IOException, InterruptedException { | ||
File logFile = run.getLogFile(); | ||
if (logFile.exists()) { | ||
boolean wasDeleted = logFile.delete(); | ||
if (!wasDeleted) { | ||
LOG.warning(String.format("Log file for build %d could not be deleted", run.getNumber())); | ||
} | ||
// ToDo: consider https://github.com/jenkinsci/delete-log-plugin/blob/master/src/main/java/jenkinsci/plugin/deletelog/LogDelete.java#L47-L51 | ||
// for this and other actions | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...mianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteLogFileAction/config.jelly
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,4 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core"> | ||
|
||
</j:jelly> |
8 changes: 8 additions & 0 deletions
8
.../damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteLogFileAction/help.html
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,8 @@ | ||
<h3>Description</h3> | ||
Deletes the build log file. | ||
|
||
<h3>Use cases</h3> | ||
To leave builds and delete the log file which eg. might contain sensitive data or are very big. | ||
|
||
<h3>Warning!</h3> | ||
Log file should not be deleted for the build which was already removed. |
25 changes: 25 additions & 0 deletions
25
...ik/jenkins/buildhistorymanager/descriptors/actions/DeleteLogFileActionDescriptorTest.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,25 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import hudson.model.Descriptor; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
public class DeleteLogFileActionDescriptorTest { | ||
|
||
@Test | ||
public void getDisplayName_ReturnsDescriptorName() { | ||
|
||
// given | ||
Descriptor descriptor = new DeleteLogFileActionDescriptor(); | ||
|
||
// when | ||
String displayName = descriptor.getDisplayName(); | ||
|
||
// then | ||
assertThat(displayName).isEqualTo("Delete log file"); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...l/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteLogFileActionTest.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,42 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.model.actions; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Test; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; | ||
|
||
/** | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
public class DeleteLogFileActionTest { | ||
|
||
@Test | ||
public void perform_OnExistingLogFile_DeletesLogFile() throws IOException, InterruptedException { | ||
|
||
// given | ||
Action action = new DeleteLogFileAction(); | ||
RunStub run = new RunStub(); | ||
run.setLogFile(true); | ||
|
||
// when | ||
action.perform(run); | ||
|
||
// then | ||
run.assertLogFileWasDeleted(); | ||
} | ||
|
||
|
||
@Test | ||
public void perform_OnMissingLogFile_SkipDeletion() throws IOException, InterruptedException { | ||
|
||
// given | ||
Action action = new DeleteLogFileAction(); | ||
RunStub run = new RunStub(); | ||
|
||
// when | ||
action.perform(run); | ||
|
||
// then | ||
run.assertLogFileWasNotDeleted(); | ||
} | ||
} |
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