-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup test results when run/job is deleted (#111)
- Loading branch information
Showing
6 changed files
with
282 additions
and
23 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
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
64 changes: 64 additions & 0 deletions
64
src/main/java/io/jenkins/plugins/junit/storage/database/TestResultCleanupListener.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,64 @@ | ||
package io.jenkins.plugins.junit.storage.database; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Item; | ||
import hudson.model.Run; | ||
import hudson.model.listeners.ItemListener; | ||
import hudson.model.listeners.RunListener; | ||
import io.jenkins.plugins.junit.storage.FileJunitTestResultStorage; | ||
import io.jenkins.plugins.junit.storage.JunitTestResultStorage; | ||
import io.jenkins.plugins.junit.storage.TestResultImpl; | ||
|
||
public class TestResultCleanupListener { | ||
|
||
@Extension | ||
public static class RunCleanupListener extends RunListener<Run> { | ||
@Override | ||
public void onDeleted(Run run) { | ||
JunitTestResultStorage junitTestResultStorage = JunitTestResultStorage.find(); | ||
if (junitTestResultStorage instanceof FileJunitTestResultStorage) { | ||
return; | ||
} | ||
|
||
if (junitTestResultStorage instanceof DatabaseTestResultStorage) { | ||
DatabaseTestResultStorage storage = (DatabaseTestResultStorage) junitTestResultStorage; | ||
if (storage.isSkipCleanupRunsOnDeletion()) { | ||
return; | ||
} | ||
} | ||
|
||
TestResultImpl testResult = junitTestResultStorage.load(run.getParent().getFullName(), run.getNumber()); | ||
|
||
if (testResult instanceof DatabaseTestResultStorage.TestResultStorage) { | ||
DatabaseTestResultStorage.TestResultStorage storage = (DatabaseTestResultStorage.TestResultStorage) testResult; | ||
|
||
storage.deleteRun(); | ||
} | ||
} | ||
} | ||
|
||
@Extension | ||
public static class JobCleanupListener extends ItemListener { | ||
@Override | ||
public void onDeleted(Item item) { | ||
JunitTestResultStorage junitTestResultStorage = JunitTestResultStorage.find(); | ||
if (junitTestResultStorage instanceof FileJunitTestResultStorage) { | ||
return; | ||
} | ||
|
||
if (junitTestResultStorage instanceof DatabaseTestResultStorage) { | ||
DatabaseTestResultStorage storage = (DatabaseTestResultStorage) junitTestResultStorage; | ||
if (storage.isSkipCleanupRunsOnDeletion()) { | ||
return; | ||
} | ||
} | ||
|
||
TestResultImpl testResult = junitTestResultStorage.load(item.getFullName(), 0); | ||
|
||
if (testResult instanceof DatabaseTestResultStorage.TestResultStorage) { | ||
DatabaseTestResultStorage.TestResultStorage storage = (DatabaseTestResultStorage.TestResultStorage) testResult; | ||
storage.deleteJob(); | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...esources/io/jenkins/plugins/junit/storage/database/DatabaseTestResultStorage/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,6 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry field="skipCleanupRunsOnDeletion"> | ||
<f:checkbox title="${%Skip cleanup of test result on build deletion}"/> | ||
</f:entry> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
...gins/junit/storage/database/DatabaseTestResultStorage/help-skipCleanupRunsOnDeletion.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,3 @@ | ||
<p>If checked tests results will not be automatically removed when a job or build is deleted.</p> | ||
|
||
<p>If you need more complex test result cleanup then please raise an issue on GitHub.</p> |
Oops, something went wrong.