Class AbstractUpload
- java.lang.Object
-
- com.google.jenkins.plugins.storage.AbstractUpload
-
- All Implemented Interfaces:
ExtensionPoint
,Describable<AbstractUpload>
,Serializable
- Direct Known Subclasses:
AbstractBucketLifecycleManager
,ClassicUpload
,StdoutUpload
public abstract class AbstractUpload extends Object implements Describable<AbstractUpload>, ExtensionPoint, Serializable
This new extension point is used for surfacing different kinds of Google Cloud Storage (GCS) uploads. The most obvious implementations are provided as:- See Also:
ClassicUpload
,We provide the following hooks for implementations to inject additional functionality: Required : provides detail information for the GCS upload report. Required : surfaces the set of for the base class to upload to GCS. Optional : determines the build states for which uploading should be performed. Optional : allows the implementation to surface additional metadata on the storage object Optional : allows the implementation to ~arbitrarily rewrite parts of the object prior to insertion.
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractUpload.UploadSpec
This tuple is used to return the modified workspace and collection ofFilePath
s to upload toperform(java.lang.String, hudson.model.AbstractBuild<?, ?>, hudson.model.TaskListener)
.-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description AbstractUpload(String bucket, UploadModule module)
Construct the base upload from a handful of universal properties.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static DescriptorExtensionList<AbstractUpload,AbstractUploadDescriptor>
all()
Gives all registeredAbstractUpload
s.protected void
annotateObject(com.google.api.services.storage.model.StorageObject object, TaskListener listener)
This hook is intended to give implementations the opportunity to further annotate theStorageObject
with metadata before uploading it to cloud storage.boolean
forResult(Result result)
Determine whether we should upload the pattern for the given build result.String
getBucket()
AbstractUploadDescriptor
getDescriptor()
abstract String
getDetails()
protected abstract AbstractUpload.UploadSpec
getInclusions(Run<?,?> run, FilePath workspace, TaskListener listener)
Implementations override this interface in order to surface the set ofFilePath
s the core logic should upload.protected Map<String,String>
getMetadata(Run<?,?> run)
Retrieves the metadata to attach to the storage object.protected UploadModule
getModule()
protected com.google.api.services.storage.model.Bucket
getOrCreateBucket(com.google.api.services.storage.Storage service, com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials credentials, com.google.jenkins.plugins.util.Executor executor, String bucketName)
Fetches or creates an instance of the bucket with the given name with the specified storage service.String
getPathPrefix()
boolean
isForFailedJobs()
boolean
isSharedPublicly()
boolean
isShowInline()
void
perform(String credentialsId, AbstractBuild<?,?> build, TaskListener listener)
This method allows the old signature for compatibility reasons.void
perform(String credentialsId, Run<?,?> run, FilePath workspace, TaskListener listener)
The main action entry point of this extension.void
setForFailedJobs(boolean forFailedJobs)
void
setPathPrefix(String pathPrefix)
void
setSharedPublicly(boolean sharedPublicly)
void
setShowInline(boolean showInline)
-
-
-
Constructor Detail
-
AbstractUpload
public AbstractUpload(String bucket, @Nullable UploadModule module)
Construct the base upload from a handful of universal properties.- Parameters:
bucket
- The unresolved name of the storage bucket within which to store the resulting objects.module
- AnUploadModule
to use for execution.
-
-
Method Detail
-
perform
public final void perform(String credentialsId, AbstractBuild<?,?> build, TaskListener listener) throws UploadException, IOException
This method allows the old signature for compatibility reasons. Callsperform(String, Run, FilePath, TaskListener)
.- Parameters:
credentialsId
- The unique ID for the credentials we are using to authenticate with GCS.build
- Current build being run.listener
- Listener for events of this job.- Throws:
UploadException
- If there was an issue uploading/accessing the GCS API.IOException
- If there was issue authenticating with credentialsId.
-
perform
public final void perform(String credentialsId, Run<?,?> run, FilePath workspace, TaskListener listener) throws UploadException, IOException
The main action entry point of this extension. This uploads the contents included by the implementation to our resolved storage bucket.- Parameters:
credentialsId
- The unique ID for the credentials we are using to authenticate with GCS.run
- Current job being run.workspace
- Workspace of node running the job.listener
- Listener for events of this job.- Throws:
UploadException
- If there was an issue uploading/accessing the GCS API.IOException
- If there was issue authenticating with credentialsId.
-
getInclusions
@Nullable protected abstract AbstractUpload.UploadSpec getInclusions(Run<?,?> run, FilePath workspace, TaskListener listener) throws UploadException
Implementations override this interface in order to surface the set ofFilePath
s the core logic should upload.- Parameters:
run
- Current job being run.workspace
- Workspace of node running the job.listener
- Listener for events of this job.- Returns:
- Set of
FilePath
s to upload. - Throws:
UploadException
- If there was an issue fetching the inclusions.- See Also:
for further details.
-
annotateObject
protected void annotateObject(com.google.api.services.storage.model.StorageObject object, TaskListener listener) throws UploadException
This hook is intended to give implementations the opportunity to further annotate theStorageObject
with metadata before uploading it to cloud storage.NOTE: The base implementation does not do anything, so calling
super.annotateObject()
is unnecessary.- Parameters:
object
- GCS object to annotate.listener
- Listener for events of this job.- Throws:
UploadException
- If there was an issue annotating the object with metadata.
-
getMetadata
protected Map<String,String> getMetadata(Run<?,?> run)
Retrieves the metadata to attach to the storage object.NOTE: This can be overriden to surface additional (or less) information.
- Parameters:
run
- Current job being run.- Returns:
- Metadata in key-value form.
-
forResult
public boolean forResult(Result result)
Determine whether we should upload the pattern for the given build result.- Parameters:
result
- Result of the build run.- Returns:
- Whether we should upload the pattern for the given build result.
-
getDetails
public abstract String getDetails()
- Returns:
- Provide detail information summarizing this download for the GCS upload report.
-
getModule
protected UploadModule getModule()
- Returns:
- The
UploadModule
for providing dependencies.
-
getBucket
public String getBucket()
- Returns:
- The bucket name specified by the user, which potentially contains unresolved symbols, such as $JOB_NAME and $BUILD_NUMBER.
-
setSharedPublicly
@DataBoundSetter public void setSharedPublicly(boolean sharedPublicly)
- Parameters:
sharedPublicly
- Whether to surface the file being uploaded to anyone with the link.
-
isSharedPublicly
public boolean isSharedPublicly()
- Returns:
- Whether to surface the file being uploaded to anyone with the link.
-
setForFailedJobs
@DataBoundSetter public void setForFailedJobs(boolean forFailedJobs)
- Parameters:
forFailedJobs
- Whether to attempt the upload, even if the job failed.
-
isForFailedJobs
public boolean isForFailedJobs()
- Returns:
- Whether to attempt the upload, even if the job failed.
-
setShowInline
@DataBoundSetter public void setShowInline(boolean showInline)
- Parameters:
showInline
- Set whether to indicate in metadata that the file should be viewable inline in web browsers, rather than requiring it to be downloaded first.
-
isShowInline
public boolean isShowInline()
- Returns:
- Whether to indicate in metadata that the file should be viewable inline in web browsers, rather than requiring it to be downloaded first.
-
setPathPrefix
@DataBoundSetter public void setPathPrefix(@Nullable String pathPrefix)
- Parameters:
pathPrefix
- The path prefix that will be stripped from uploaded files. May be null if no path prefix needs to be stripped.Filenames that do not start with this prefix will not be modified. Trailing slash is automatically added if it is missing.
-
getPathPrefix
@Nullable public String getPathPrefix()
- Returns:
- The path prefix that will be stripped from uploaded files. May be null if no path
prefix needs to be stripped.
Filenames that do not start with this prefix will not be modified. Trailing slash is automatically added if it is missing.
-
all
public static DescriptorExtensionList<AbstractUpload,AbstractUploadDescriptor> all()
Gives all registeredAbstractUpload
s. See: https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point- Returns:
- All registered
AbstractUpload
s.
-
getDescriptor
public AbstractUploadDescriptor getDescriptor()
- Specified by:
getDescriptor
in interfaceDescribable<AbstractUpload>
-
getOrCreateBucket
protected com.google.api.services.storage.model.Bucket getOrCreateBucket(com.google.api.services.storage.Storage service, com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials credentials, com.google.jenkins.plugins.util.Executor executor, String bucketName) throws UploadException
Fetches or creates an instance of the bucket with the given name with the specified storage service.- Parameters:
service
- Handle to the GCS API.credentials
- The credentials with which to fetch/create the bucketexecutor
- Helper class to make calls to the GCS API.bucketName
- The top-level bucket name to ensure exists- Returns:
- an instance of the named bucket, created or retrieved.
- Throws:
UploadException
- if any issues are encountered
-
-