Using Placeholders
JFrog CLI provides flexibility in how you download, upload, copy, or move files through the use of wildcard or regular expressions with placeholders.
Any wildcard expression enclosed in parentheses in the source path can be matched with a corresponding placeholder (e.g., {1}) in the target path. This allows you to dynamically determine the destination path and filename for an artifact.
How Placeholders Work
| Component | Description |
|---|---|
(*) | Capture group in source pattern - matches any characters |
{1} | First placeholder - references first capture group |
{2} | Second placeholder - references second capture group |
{n} | Nth placeholder - references nth capture group |
Using Placeholder Examples
Example 1: Upload Files into Dynamically Named Directories
This example uploads each .tgz file from the source into a new directory in the target repository that matches the file's base name. For example, the file froggy.tgz is uploaded to my-local-repo/froggy/, which creates the froggy folder in Artifactory.
jf rt u "(*).tgz" my-local-repo/{1}/ --recursive=falseBreakdown:
| Pattern Part | Description |
|---|---|
(*).tgz | Captures the filename (without extension) into group 1 |
{1}/ | Uses the captured filename as the directory name |
--recursive=false | Only processes files in the current directory (default is true) |
Result:
| Source File | Target Path |
|---|---|
froggy.tgz | my-local-repo/froggy/froggy.tgz |
ribbit.tgz | my-local-repo/ribbit/ribbit.tgz |
Example 2: Upload Files with Modified Names
This example uploads all files with names that begin with frog to the frogfiles folder, appending the suffix -up to each filename. For example, a file named froggy.tgz is renamed to froggy.tgz-up.
jf rt u "(frog*)" my-local-repo/frogfiles/{1}-up --recursive=falseBreakdown:
| Pattern Part | Description |
|---|---|
(frog*) | Captures filenames starting with "frog" into group 1 |
{1}-up | Appends "-up" suffix to the captured filename |
--recursive=false | Only processes files in the current directory |
Result:
| Source File | Target Path |
|---|---|
froggy.tgz | my-local-repo/frogfiles/froggy.tgz-up |
frog-lib.jar | my-local-repo/frogfiles/frog-lib.jar-up |
Example 3: Organize Uploaded Files by Extension
This example uploads all files from the current directory into the my-local-repo repository, placing them into subdirectories named after their file extensions.
jf rt u "(*).(*)" my-local-repo/{2}/{1}.{2} --recursive=falseBreakdown:
| Pattern Part | Description |
|---|---|
(*).(*) | Captures filename (group 1) and extension (group 2) |
{2}/ | Uses extension as directory name |
{1}.{2} | Reconstructs original filename |
--recursive=false | Only processes files in the current directory |
Result:
| Source File | Target Path |
|---|---|
froggy.tgz | my-local-repo/tgz/froggy.tgz |
ribbit.zip | my-local-repo/zip/ribbit.zip |
pond.jar | my-local-repo/jar/pond.jar |
Example 4: Copy Files and Append a Suffix
This example copies all .zip files from the rabbit/ directory in the source-frog-repo to the same path in the target-frog-repo and appends .cp to each copied filename.
jf rt cp "source-frog-repo/rabbit/(*.zip)" target-frog-repo/rabbit/{1}.cpBreakdown:
| Pattern Part | Description |
|---|---|
source-frog-repo/rabbit/(*.zip) | Captures .zip filenames from source path |
target-frog-repo/rabbit/{1}.cp | Places files in target with .cp suffix |
Result:
| Source Path | Target Path |
|---|---|
source-frog-repo/rabbit/archive.zip | target-frog-repo/rabbit/archive.zip.cp |
source-frog-repo/rabbit/data.zip | target-frog-repo/rabbit/data.zip.cp |
Command Reference
Supported Commands
Placeholders are supported in the following commands:
| Command | Abbreviation | Description |
|---|---|---|
jf rt upload | jf rt u | Upload files to Artifactory |
jf rt download | jf rt dl | Download files from Artifactory |
jf rt copy | jf rt cp | Copy files within Artifactory |
jf rt move | jf rt mv | Move files within Artifactory |
Relevant Flags
| Flag | Default | Description |
|---|---|---|
--recursive | true | When true, collects files from sub-folders. Set to false to process only the current directory. |
--flat | false | When true, ignores source directory structure. When false, preserves hierarchy. |
--regexp | false | When true, interprets the pattern as a regular expression instead of wildcards. |
Advanced Usage
Using Regular Expressions with Placeholders
When using --regexp, you can use regex capture groups instead of wildcard patterns:
jf rt u "(.+)-sources\.jar" libs-release-local/{1}/ --regexpThis captures the artifact name before -sources.jar and uses it as a directory.
Multiple Capture Groups
You can use multiple capture groups and reference them in any order:
jf rt u "(org)/(module)/(*).jar" my-repo/{2}/{1}/{3}.jarFile Spec Usage
Placeholders also work in File Specs:
{
"files": [
{
"pattern": "(*).tgz",
"target": "my-local-repo/{1}/",
"recursive": "false"
}
]
}Updated 2 months ago
