Skip to content
Browse files
[JENKINS-51819] When using a custom ArtifactManager, Run.delete must …
…call ArtifactManager.delete.
  • Loading branch information
jglick committed Jun 8, 2018
1 parent 64e4679 commit 9b0a0e71b8a6b92227e6af80ec7202aa0bf44b5b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
@@ -1554,6 +1554,10 @@ public void delete() throws IOException {


if (artifactManager != null) {
} // for StandardArtifactManager, deleting the whole build dir suffices

synchronized (this) { // avoid holding a lock while calling plugin impls of onDeleted
File tmp = new File(rootDir.getParentFile(),'.'+rootDir.getName());

@@ -23,19 +23,30 @@
package hudson.model;

import hudson.FilePath;
import hudson.Launcher;
import hudson.tasks.ArtifactArchiver;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import jenkins.model.ArtifactManager;
import jenkins.model.ArtifactManagerConfiguration;
import jenkins.model.ArtifactManagerFactory;
import jenkins.model.ArtifactManagerFactoryDescriptor;
import jenkins.model.Jenkins;
import jenkins.util.VirtualFile;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

* @author Kohsuke Kawaguchi
public class RunTest {

@Rule public JenkinsRule j = new JenkinsRule();
@@ -73,4 +84,33 @@ public class RunTest {
assertEquals(Run.KeepLogBuildBadge.class, badgeActions.get(0).getClass());

@Test public void deleteArtifactsCustom() throws Exception {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(new Mgr.Factory());
FreeStyleProject p = j.createFreeStyleProject();
j.jenkins.getWorkspaceFor(p).child("f").write("", null);
p.getPublishersList().add(new ArtifactArchiver("f"));
FreeStyleBuild b = j.buildAndAssertSuccess(p);
private static final class Mgr extends ArtifactManager {
static final AtomicBoolean deleted = new AtomicBoolean();
@Override public boolean delete() throws IOException, InterruptedException {
return !deleted.getAndSet(true);
@Override public void onLoad(Run<?, ?> build) {}
@Override public void archive(FilePath workspace, Launcher launcher, BuildListener listener, Map<String, String> artifacts) throws IOException, InterruptedException {}
@Override public VirtualFile root() {
return VirtualFile.forFile(Jenkins.get().getRootDir()); // irrelevant
public static final class Factory extends ArtifactManagerFactory {
@DataBoundConstructor public Factory() {}
@Override public ArtifactManager managerFor(Run<?, ?> build) {
return new Mgr();
@TestExtension("deleteArtifactsCustom") public static final class DescriptorImpl extends ArtifactManagerFactoryDescriptor {}


0 comments on commit 9b0a0e7

Please sign in to comment.