This method should be used when existing artifacts are to be loaded, displayed, or removed.
+ * If adding artifacts, use {@link #pickArtifactManager} instead.
+ * @return an appropriate artifact manager
+ * @since 1.531
+ */
+ public final @Nonnull ArtifactManager getArtifactManager() {
+ return artifactManager != null ? artifactManager : new StandardArtifactManager(this);
+ }
+
+ /**
+ * Selects an object responsible for storing and retrieving build artifacts.
+ * The first time this is called on a running build, {@link ArtifactManagerConfiguration} is checked
+ * to see if one will handle this build.
+ * If so, that manager is saved in the build and it will be used henceforth.
+ * If no manager claimed the build, {@link StandardArtifactManager} is used.
+ * This method should be used when a build step expects to archive some artifacts.
+ * If only displaying existing artifacts, use {@link #getArtifactManager} instead.
+ * @return an appropriate artifact manager
+ * @throws IOException if a custom manager was selected but the selection could not be saved
+ * @since 1.531
+ */
+ public final synchronized @Nonnull ArtifactManager pickArtifactManager() throws IOException {
+ if (artifactManager != null) {
+ return artifactManager;
+ } else {
+ for (ArtifactManagerFactory f : ArtifactManagerConfiguration.get().getArtifactManagerFactories()) {
+ ArtifactManager mgr = f.managerFor(this);
+ if (mgr != null) {
+ artifactManager = mgr;
+ save();
+ return mgr;
+ }
+ }
+ return new StandardArtifactManager(this);
+ }
+ }
+
/**
* Gets the directory where the artifacts are archived.
+ * @deprecated Should only be used from {@link StandardArtifactManager} or subclasses.
*/
+ @Deprecated
public File getArtifactsDir() {
return new File(getRootDir(),"archive");
}
@@ -984,7 +1040,11 @@ public abstract class Run ,RunT extends Run getArtifactsUpTo(int n) {
ArtifactList r = new ArtifactList();
- addArtifacts(getArtifactsDir(),"","",r,null,n);
+ try {
+ addArtifacts(getArtifactManager().root(), "", "", r, null, n);
+ } catch (IOException x) {
+ LOGGER.log(Level.WARNING, null, x);
+ }
r.computeDisplayName();
return r;
}
@@ -999,18 +1059,17 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run files = ws.act(new ListFiles(artifacts, excludes));
+ if (!files.isEmpty()) {
+ build.pickArtifactManager().archive(ws, launcher, listener, files);
+ } else {
Result result = build.getResult();
if (result != null && result.isBetterOrEqualTo(Result.UNSTABLE)) {
// If the build failed, don't complain that there was no matching artifact.
@@ -165,6 +169,23 @@ public class ArtifactArchiver extends Recorder {
return true;
}
+ private static final class ListFiles implements FilePath.FileCallable