public abstract class AbstractUpload extends Object implements Describable<AbstractUpload>, ExtensionPoint, Serializable
ClassicUpload
,
We provide the following hooks for implementations to inject additional functionality:
- Required {@link #getDetails}: provides detail information for the GCS upload report.
- Required {@link #getInclusions}: surfaces the set of {@link UploadSpec} for the base
class to upload to GCS.
- Optional {@link #forResult}: determines the build states for which uploading should be
performed.
- Optional {@link #getMetadata}: allows the implementation to surface additional metadata
on the storage object
- Optional {@link #annotateObject}: allows the implementation to ~arbitrarily rewrite
parts of the object prior to insertion.
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected static class |
AbstractUpload.UploadSpec
This tuple is used to return the modified workspace and collection of
FilePath s to
upload to perform(java.lang.String, hudson.model.AbstractBuild<?, ?>, hudson.model.TaskListener) . |
ExtensionPoint.LegacyInstancesAreScopedToHudson
Constructor and Description |
---|
AbstractUpload(String bucket,
UploadModule module)
Construct the base upload from a handful of universal properties.
|
Modifier and Type | Method and Description |
---|---|
static DescriptorExtensionList<AbstractUpload,AbstractUploadDescriptor> |
all()
Gives all registered
AbstractUpload 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 the
StorageObject 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 of
FilePath 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) |
public AbstractUpload(String bucket, @Nullable UploadModule module)
bucket
- The unresolved name of the storage bucket within which to store the resulting
objects.module
- An UploadModule
to use for execution.public final void perform(String credentialsId, AbstractBuild<?,?> build, TaskListener listener) throws UploadException, IOException
perform(String,
Run, FilePath, TaskListener)
.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.UploadException
- If there was an issue uploading/accessing the GCS API.IOException
- If there was issue authenticating with credentialsId.public final void perform(String credentialsId, Run<?,?> run, FilePath workspace, TaskListener listener) throws UploadException, IOException
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.UploadException
- If there was an issue uploading/accessing the GCS API.IOException
- If there was issue authenticating with credentialsId.@Nullable protected abstract AbstractUpload.UploadSpec getInclusions(Run<?,?> run, FilePath workspace, TaskListener listener) throws UploadException
FilePath
s the
core logic should upload.run
- Current job being run.workspace
- Workspace of node running the job.listener
- Listener for events of this job.FilePath
s to upload.UploadException
- If there was an issue fetching the inclusions.for further details.
protected void annotateObject(com.google.api.services.storage.model.StorageObject object, TaskListener listener) throws UploadException
StorageObject
with metadata before uploading it to cloud storage.
NOTE: The base implementation does not do anything, so calling super.annotateObject()
is unnecessary.
object
- GCS object to annotate.listener
- Listener for events of this job.UploadException
- If there was an issue annotating the object with metadata.protected Map<String,String> getMetadata(Run<?,?> run)
NOTE: This can be overriden to surface additional (or less) information.
run
- Current job being run.public boolean forResult(Result result)
result
- Result of the build run.public abstract String getDetails()
protected UploadModule getModule()
UploadModule
for providing dependencies.public String getBucket()
@DataBoundSetter public void setSharedPublicly(boolean sharedPublicly)
sharedPublicly
- Whether to surface the file being uploaded to anyone with the link.public boolean isSharedPublicly()
@DataBoundSetter public void setForFailedJobs(boolean forFailedJobs)
forFailedJobs
- Whether to attempt the upload, even if the job failed.public boolean isForFailedJobs()
@DataBoundSetter public void setShowInline(boolean showInline)
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.public boolean isShowInline()
@DataBoundSetter public void setPathPrefix(@Nullable String pathPrefix)
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.
@Nullable public String getPathPrefix()
Filenames that do not start with this prefix will not be modified. Trailing slash is automatically added if it is missing.
public static DescriptorExtensionList<AbstractUpload,AbstractUploadDescriptor> all()
AbstractUpload
s. See:
https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+pointAbstractUpload
s.public AbstractUploadDescriptor getDescriptor()
getDescriptor
in interface Describable<AbstractUpload>
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
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 existsUploadException
- if any issues are encounteredCopyright © 2016–2019. All rights reserved.