Reputation: 9219
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?
Upvotes: 1
Views: 467
Reputation: 470
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.
Upvotes: 1