ARTIFACTORY: Can’t copy artifacts from remote repo to local repo

ARTIFACTORY: Can’t copy artifacts from remote repo to local repo

AuthorFullName__c
Sara Ngo
articleNumber
000005851
ft:sourceType
Salesforce
FirstPublishedDate
2023-08-28T18:59:21Z
lastModifiedDate
2023-08-28
VersionNumber
1
Issue:
Some users may encounter issues when trying to copy an artifact from a remote repo to a local repo using the Copy Item REST API:
POST /api/copy/{srcRepoKey}/{srcFilePath}?to=/{targetRepoKey}/{targetFilePath}[&dry=1][&suppressLayouts=0/1(default)][&failFast=0/1]


For example:
curl –uadmin -XPOST http://localhost:8081/artifactory/api/copy/test-maven-remote/accent/accent/0.1.1/accent-0.1.1.jar?to=/test-repo/test-copy-2

Output:
{
  "messages" : [ {
    "level" : "ERROR",
    "message" : "Failed to copy from src=test-maven-remote/accent/accent/0.1.1/accent-0.1.1.jar to target=/test-repo/test-copy-2: Attempt to lock 'test-maven-remote:accent/accent/0.1.1/accent-0.1.1.jar' with repository 'test-maven-remote-cache"
  } ]
}

Explanation:
Artifactory stores artifacts retrieved from a remote repository in a local cache, which will be ended by ’-cache’ (i.e. <remote-repo-name>-cache). Therefore, the REST API for copying items will be supported by local & remote-cache repositories.

Solution:
To overcome this issue, users can perform the same REST API call against the <remote-repo-name>-cache repo instead of the remote repo.

For example:
curl -uadmin -XPOST http://localhost:8081/artifactory/api/copy/test-maven-remote-cache/ccent/accent/0.1.1/accent-0.1.1.jar?to=/test-repo/test-copy-2wow

Output:
{
  "messages" : [ {
    "level" : "INFO",
    "message" : "copying test-maven-remote-cache:accent/accent/0.1.1/accent-0.1.1.jar to test-repo:test-copy-2 completed successfully, 1 artifacts and 0 folders were copied"
  } ]
}

In case the file doesn't exist in remote-cache, means Artifactory doesn't have its content to process the copy request, user can download the artifact or use the Artifact Sync REST API to get pre-populate the repo cache before doing the copy.