Is there a way to push a docker image to a registry without doing the docker.build part?

Is there a way to push a docker image to a registry, without doing the docker.build part?

Context: This is a project built with spring boot using jdk17 and basically the image is being built but we still need to push this to our private registry.

Side note: we only work with scripted pipelines

What you normally do is something similar to this (which we’re already doing in other projects):

    docker.withRegistry('https://registry.example.com', 'credentials-id') {

        def customImage = docker.build("my-image:${env.BUILD_ID}")

        /* Push the container to the custom Registry */
        customImage.push()
    }

But we don’t need this part docker.build("my-image:${env.BUILD_ID}") and cant find a way of doing push() without it. We’re not using Dockerfiles.

Every piece of documentation I’ve found so far uses the docker.build part. I’m really running out of ideas and solutions for this.

Thanks in advance!!

docker.build calls docker build then wraps it in a docker.image() - https://github.com/jenkinsci/docker-workflow-plugin/blob/d5d2e5c4007f7ea006152542b2bcbe0f1b2b08aa/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy#L86-L96

so you could do def image = docker.image(“originalimagename”) // assumes that the image is already on the agent
you might be able do image.pull() or something. I’m just guessing looking at the script

then you can do image.tag(“foobar”) and image.push(“foobar”)

That being said, I find these “helpers” not helpful at all, and would recommend just using cli docker build docker tag docker push etc