Skip to content
Permalink
Browse files
[JENKINS-51523] Move constants to S3BlobStore
and add a new one for separately control stash deletion
  • Loading branch information
carlossg committed May 24, 2018
1 parent 735de30 commit 11f2455c9e006842b95606903b05bf41223f32bb
@@ -59,6 +59,14 @@ public enum HttpMethod {
@NonNull
public abstract String getContainer();

/** A constant to define whether we should delete blobs or leave them to be managed on the blob service side. */
@NonNull
public abstract boolean isDeleteBlobs();

/** A constant to define whether we should delete stashes or leave them to be managed on the blob service side. */
@NonNull
public abstract boolean isDeleteStashes();

/** Creates the jclouds handle for working with blobs. */
@NonNull
public abstract BlobStoreContext getContext() throws IOException;
@@ -75,8 +75,6 @@ public final class JCloudsArtifactManager extends ArtifactManager implements Sta

private static final Logger LOGGER = Logger.getLogger(JCloudsArtifactManager.class.getName());

private static boolean DELETE_BLOBS = Boolean.getBoolean(JCloudsArtifactManager.class.getName() + ".deleteBlobs");

private final BlobStoreProvider provider;

private transient String key; // e.g. myorg/myrepo/master/123
@@ -131,7 +129,12 @@ public void archive(FilePath workspace, Launcher launcher, BuildListener listene

@Override
public boolean delete() throws IOException, InterruptedException {
return DELETE_BLOBS ? delete(provider, getContext().getBlobStore(), getBlobPath("")) : false;
String blobPath = getBlobPath("");
if (!provider.isDeleteBlobs()) {
LOGGER.log(Level.FINEST, "Ignoring blob deletion: {0}", blobPath);
return false;
}
return delete(provider, getContext().getBlobStore(), blobPath);
}

/**
@@ -248,6 +251,12 @@ public Void invoke(File f, VirtualChannel channel) throws IOException, Interrupt
@Override
public void clearAllStashes(TaskListener listener) throws IOException, InterruptedException {
String stashPrefix = getBlobPath("stashes/");

if (!provider.isDeleteStashes()) {
LOGGER.log(Level.FINEST, "Ignoring stash deletion: {0}", stashPrefix);
return;
}

BlobStore blobStore = getContext().getBlobStore();
Iterator<StorageMetadata> it = new JCloudsVirtualFile.PageSetIterable(blobStore, provider.getContainer(), ListContainerOptions.Builder.prefix(stashPrefix).recursive());
int count = 0;
@@ -24,8 +24,6 @@

package io.jenkins.plugins.artifact_manager_s3;

import io.jenkins.plugins.artifact_manager_jclouds.BlobStoreProvider;
import io.jenkins.plugins.artifact_manager_jclouds.BlobStoreProviderDescriptor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -56,6 +54,8 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import io.jenkins.plugins.artifact_manager_jclouds.BlobStoreProvider;
import io.jenkins.plugins.artifact_manager_jclouds.BlobStoreProviderDescriptor;
import shaded.com.google.common.base.Supplier;

/**
@@ -74,6 +74,10 @@ public class S3BlobStore extends BlobStoreProvider {
private static String BLOB_CONTAINER = System.getenv("S3_BUCKET");
@SuppressWarnings("FieldMayBeFinal")
private static String PREFIX = System.getenv("S3_DIR");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DELETE_BLOBS = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteBlobs");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DELETE_STASHES = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteStashes");

@DataBoundConstructor
public S3BlobStore() {}
@@ -88,6 +92,16 @@ public String getContainer() {
return BLOB_CONTAINER;
}

@Override
public boolean isDeleteBlobs() {
return DELETE_BLOBS;
}

@Override
public boolean isDeleteStashes() {
return DELETE_STASHES;
}

@Override
public BlobStoreContext getContext() throws IOException {
LOGGER.log(Level.FINEST, "Building context");

0 comments on commit 11f2455

Please sign in to comment.