'Unable to copy docker image in JFrog Artifactory from one repo to a target repo

We have an Artifactory server to host our Docker images. I am trying to effectively re-tag one of my Docker images using the JFrog API. I know I could do this with a simple docker tag and docker push, but wanted to see how to do this more directly with the Artifactory API. Unfortunately I am running into a snag. Here's the API call I'm trying to make:

curl -X POST --user '[email protected]:MyAPIKey' -H "Content-Type: application/json" --data \
  '{"targetRepo": "docker-local", "dockerRepository": "docker-local", "tag": "my/docker/image/original", "targetTag": "my/docker/image/new", "copy": true}' \
  https://www.myartifactoryserver.com/api/docker/docker-local/v2/promote

But this call returns the following error:

{
  "errors" : [ {
    "status" : 400,
    "message" : "'targetTag' tag value is invalid."
  } ]
}

I'm not sure what I'm doing wrong here, especially since I am able to perform this same copy using the UI. How do I do it with the API?



Solution 1:[1]

Dror Bereznitsky's answer is spot on if you want to do simple re-tagging like

    demo-app:1.0.1 ? demo-app:latest

However, if your tag is path-like, you can, using Artifactory terminology, promote an Image into a different "Repository Path" within the same "Repository" and keep the same "Tag" (version) in both places:

    com.example/stage/demo-app:1.0.1 ? com.example/release/demo-app:1.0.1

To promote an Image from stage to release like this:

Artifactory screenshot

execute POST request with following body:

POST /api/docker/devops-docker-local/v2/promote

{
    "repository"             : "devops-docker-local",          // Source Repository
    "dockerRepository"       : "com.example/stage/demo-app",   // Source Path
    "tag"                    : "1.0.1",                        // Source Tag

    "targetRepo"             : "devops-docker-local",          // Target Repository
    "targetDockerRepository" : "com.example/release/demo-app", // Target Path
    "targetTag"              : "1.0.1",                        // Target Tag

    "copy": true
}

The API was tested and screenshot taken on with Artifactory EnterpriseX license 7.33.8 rev 73308900

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 curd0