Class DownloadStep

    • Constructor Detail

      • DownloadStep

        @DataBoundConstructor
        public DownloadStep​(String credentialsId,
                            String bucketUri,
                            String localDirectory)
        DataBoundConstructor for DownloadStep.
        Parameters:
        credentialsId - The unique ID for the credentials we are using to authenticate with GCS.
        bucketUri - Name of the GCS bucket. e.g. gs://MY_BUCKET_NAME
        localDirectory - Path of the local directory in Jenkins to download the file to.
      • DownloadStep

        public DownloadStep​(String credentialsId,
                            String bucketUri,
                            String localDirectory,
                            @Nullable
                            UploadModule module)
        Constructor for DownloadStep.
        Parameters:
        credentialsId - The unique ID for the credentials we are using to authenticate with GCS.
        bucketUri - Name of the GCS bucket. e.g. gs://MY_BUCKET_NAME
        localDirectory - Path of the local directory in Jenkins to download the file to.
        module - An UploadModule to use for execution.
    • Method Detail

      • getBucketUri

        public String getBucketUri()
        Returns:
        The bucket uri specified by the user, which potentially contains unresolved symbols, such as $JOB_NAME and $BUILD_NUMBER.
      • getLocalDirectory

        public String getLocalDirectory()
        Returns:
        The local directory in the Jenkins workspace that will receive the files. This might contain unresolved symbols, such as $JOB_NAME and $BUILD_NUMBER.
      • setPathPrefix

        @DataBoundSetter
        public void setPathPrefix​(@Nullable
                                  String pathPrefix)
        Parameters:
        pathPrefix - The path prefix that will be stripped from downloaded 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 downloaded 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.

      • getModule

        protected UploadModule getModule()
        Returns:
        The UploadModule used for providing dependencies.
      • getCredentialsId

        public String getCredentialsId()
        Returns:
        The unique ID for the credentials we are using to authenticate with GCS.
      • getCredentials

        public com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials getCredentials()
        Returns:
        The credentials we are using to authenticate with GCS.
      • perform

        public void perform​(@NonNull
                            Run<?,​?> run,
                            @NonNull
                            FilePath workspace,
                            @NonNull
                            Launcher launcher,
                            @NonNull
                            TaskListener listener)
                     throws IOException,
                            InterruptedException
        The main entry point of this extension. Downloads the resolved GCS objects from the resolved GCS bucket to a local directory.
        Specified by:
        perform in interface SimpleBuildStep
        Parameters:
        run - Current job being run.
        workspace - Workspace of node running the job.
        launcher - Launcher for this job.
        listener - Listener for events of this job.
        Throws:
        IOException - If there was an issue parsing the bucket URI.
        InterruptedException - If there was an issue initiating downloads at workspace or expanding variables in the pathPrefix.
      • split

        public static String[] split​(String uri)
                              throws AbortException
        Split the string on wildcards ("*").

        String.split removes trailing empty strings, for example, "a", "a*" and "a**" and would produce the same result, so that method is not suitable.

        Parameters:
        uri - URI supplied to be split.
        Returns:
        URI split by "*" wildcard.
        Throws:
        AbortException - If there is more than one wild card character in the provided string.