1

When pushing a Docker image to Artifactory from Jenkins, using the JFrog plugin, both the scripted and declarative syntax expect an image and a targetRepo parameter. The documentation isn't overly clear what these should be, but a little playing around seems to suggest:

  • image: The Artifactory image tag, including the Artifactory registry URL (e.g., artifactory.example.com/my-docker-registry/my-image:latest)
  • targetRepo: The tag of the image that was built locally to Jenkins that you want to push (e.g., my-image:SOME_GIT_COMMIT).

However, this only seems to work if you explicitly retag your image first. Otherwise it complains with an "Image not found" error:

stage("Push image to Artifactory") {
  steps {
    // Step 1: Retag the built image with the Artifactory repository tag
    sh "docker tag ${tag} ${artifactory_tag}"

    // Step 2: Push the newly tagged image
    rtDockerPush (
      serverId: artifactory_server,
      image: artifactory_tag,
      targetRepo: tag
    )

    // Step 3: Publish the build info
    rtPublishBuildInfo (
      serverId: artifactory_server
    )
  }
}

Why do I have to retag the image, since all the information is available to rtDockerPush; why can't it do the retagging? Or, alternatively, does targetRepo not mean what I think it means, despite it seeming to work under my assumptions?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Xophmeister
  • 8,884
  • 4
  • 44
  • 87

1 Answers1

1

targetRepo is the repository in Artifactory where we would like to push the image to. Please check if a definition like the below in the pipeline is helpful to simplify both tagging and target configuration in the same step?

def buildInfo = rtDocker.push '<artifactoryDockerRegistry>/hello-world:latest', '<targetRepo>'

Also, please check if this answer is useful, that includes a working pipeline example.

Yuvarajan
  • 450
  • 2
  • 5
  • I don't understand the difference between the Artifactory repository and the Artifactory Docker registry? For example, if I want to push `artifactory.example.com/my-docker-registry/my-image:latest` then isn't the Artifactory repository `my-docker-registry`? That would be redundant, so I suspect my understanding is completely wrong... – Xophmeister Sep 15 '22 at 16:38