Ant regular expressions offer powerful options to adjust the resulting object keys on S3 uploads, but they are not exactly intuitive to use. This article offers some examples for common use cases to get you started.
Using Ant regular expressions on S3 uploads in itself is straight forward:
Check the Use Ant regular expressions to rename files checkbox.
Fill the appearing From Pattern and To Pattern fields.
Common use cases
The tricky part can be defining the right patterns for the desired result, hence some common examples:
Rename a single file
This is the most basic operation, but comes with a caveat regarding the need to escape the '.' for literal matching in the from pattern:
Drop leading local path elements
(example from screenshot above)
When you select local files, their full path relative to the Bamboo working directory will become part of the resulting object key on upload, e.g. "some/local/path/file.txt" would result in "[optionalObjectKeyPrefix/]some/local/path/file.txt". In order to drop parts of the local path, you would use subexpression capturing groups via parentheses to capture only the part you are interested in:
Drop intermediate path elements
Assuming you have a nested directory structure as the source, but want to remove parts of that nesting (e.g. "a/b/c/someArtifact.jar" and "a/b/d/anotherArtifact.jar" and you want to drop the c and d subdirectories):
Note the 'non greedy' ? operator to prevent matching more than one directory level between the two!
In case you need to use end of line matching in your from patterns, note that you need to escape a dollar-sign ($) with another dollar-sign in Ant!