提交 a71240c8 编写于 作者: O Oleg Nenashev

Merge pull request #1205 from daniel-beck/JENKINS-22699

[FIXED JENKINS-22699] - JUnit Archiver. Add option to archive only when successful
......@@ -74,16 +74,26 @@ public class ArtifactArchiver extends Recorder {
@Nonnull
private Boolean allowEmptyArchive;
/**
* Archive only if build is successful, skip archiving on failed builds.
*/
private boolean onlyIfSuccessful;
public ArtifactArchiver(String artifacts, String excludes, boolean latestOnly) {
this(artifacts, excludes, latestOnly, false);
this(artifacts, excludes, latestOnly, false, false);
}
@DataBoundConstructor
public ArtifactArchiver(String artifacts, String excludes, boolean latestOnly, boolean allowEmptyArchive) {
this(artifacts, excludes, latestOnly, allowEmptyArchive, false);
}
@DataBoundConstructor
public ArtifactArchiver(String artifacts, String excludes, boolean latestOnly, boolean allowEmptyArchive, boolean onlyIfSuccessful) {
this.artifacts = artifacts.trim();
this.excludes = Util.fixEmptyAndTrim(excludes);
this.latestOnly = latestOnly;
this.allowEmptyArchive = allowEmptyArchive;
this.onlyIfSuccessful = onlyIfSuccessful;
}
// Backwards compatibility for older builds
......@@ -106,6 +116,10 @@ public class ArtifactArchiver extends Recorder {
return latestOnly;
}
public boolean isOnlyIfSuccessful() {
return onlyIfSuccessful;
}
public boolean getAllowEmptyArchive() {
return allowEmptyArchive;
}
......@@ -126,6 +140,11 @@ public class ArtifactArchiver extends Recorder {
return true;
}
if (build.getResult().isWorseThan(Result.UNSTABLE) && onlyIfSuccessful) {
listener.getLogger().println(Messages.ArtifactArchiver_SkipBecauseOnlyIfSuccessful());
return true;
}
listener.getLogger().println(Messages.ArtifactArchiver_ARCHIVING_ARTIFACTS());
try {
FilePath ws = build.getWorkspace();
......
......@@ -37,5 +37,8 @@ THE SOFTWARE.
<f:entry field="allowEmptyArchive" >
<f:checkbox title="${%allowEmptyArchive}"/>
</f:entry>
<f:entry field="onlyIfSuccessful" >
<f:checkbox title="${%onlyIfSuccessful}"/>
</f:entry>
</f:advanced>
</j:jelly>
\ No newline at end of file
......@@ -21,4 +21,5 @@
# THE SOFTWARE.
lastBuildOnly=Discard all but the last successful/stable artifact to save disk space
allowEmptyArchive=Do not fail build if archiving returns nothing
\ No newline at end of file
allowEmptyArchive=Do not fail build if archiving returns nothing
onlyIfSuccessful=Archive artifacts only if build is successful
\ No newline at end of file
......@@ -31,6 +31,7 @@ Ant.ProjectConfigNeeded= Maybe you need to configure the job to choose one of yo
ArtifactArchiver.ARCHIVING_ARTIFACTS=Archiving artifacts
ArtifactArchiver.DeletingOld=Deleting old artifacts from {0}
ArtifactArchiver.DisplayName=Archive the artifacts
ArtifactArchiver.SkipBecauseOnlyIfSuccessful=Skipped archiving because build is not successful
ArtifactArchiver.FailedToArchive=Failed to archive artifacts: {0}
ArtifactArchiver.NoIncludes=\
No artifacts are configured for archiving.\n\
......
......@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.AbortException;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
......@@ -253,4 +254,25 @@ public class ArtifactArchiverTest {
}
}
static class CreateArtifactAndFail extends TestBuilder {
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
build.getWorkspace().child("f").write("content", "UTF-8");
throw new AbortException("failing the build");
}
}
@Test
@Bug(22698)
public void testArchivingSkippedWhenOnlyIfSuccessfulChecked() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
project.getPublishersList().replaceBy(Collections.singleton(new ArtifactArchiver("f", "", false, false, false)));
project.getBuildersList().replaceBy(Collections.singleton(new CreateArtifactAndFail()));
assertEquals(Result.FAILURE, build(project));
assertTrue(project.getBuildByNumber(1).getHasArtifacts());
project.getPublishersList().replaceBy(Collections.singleton(new ArtifactArchiver("f", "", false, false, true)));
assertEquals(Result.FAILURE, build(project));
assertTrue(project.getBuildByNumber(1).getHasArtifacts());
assertFalse(project.getBuildByNumber(2).getHasArtifacts());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册