We can specify the source path while using the step “Upload Artifacts to S3” in CI pipeline. We also have the target path config available to specify the path to store the file in S3, relative to the bucket. More details about all the available configuration for the step “Upload Artifacts to S3” can be referred here
If the source file is in the path “/harness/test/file1.txt” for example, and if we have the source path set as “test/*” and the target configured as “target-folder”, once the file has been uploaded to s3 via the “Upload Artifacts to S3” step, the file will be in the below path in the S3 bucket.
<bucketname>/target-folder/test/file1.txt
In order to avoid uploading the whole folder structure of the source path to S3 bucket but only drop the file to the specified bucket target path, you can use a stage variable with the name PLUGIN_STRIP_PREFIX and the value as the file prefix which needs to be trimmed from the full path.
From the above example, if we want to trim the prefix “test” from the source file path, we can configure the stage variable as below.