Class AbstractUpload

    • 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 - An UploadModule to use for execution.
    • Method Detail

      • 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.
      • 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 the StorageObject 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.
      • 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.

      • 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 bucket
        executor - 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