jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-45152] Should be able to check if image exists

Open
#506 0 comments 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin enhancement imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

Description

Right now, you can do:

dimage = docker.image("whatever/whatever:99")

This seems fine, until you try to spin up a container, where it throws an exception (that you can catch, which is great).

dimage.withRun() { /* do nothing; just attempt to spin up container */ }

The problem is that takes some time on a loaded server, because it spins up a container for no real reason.

I would like a "validate" method. If that verb is too "heavy" and implies too much, "exists" would be fine, e.g.:

dimage = docker.image("whatever/whatever:99")

if (dimage.exists()) {
...
}

Workaround:

image_id = sh (script: "docker images -q whatever/whatever:99", returnStdout: true).trim()

if (image_id.isEmpty()) throw new Exception("Image not found")

---
Originally reported by aarondmarasco_vsi, imported from: Should be able to check if image exists


  • status: Open
  • priority: Minor
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 3
  • watchers: 4
  • imported: 2025-12-07

Raw content of original issue

Right now, you can do:



dimage = docker.image("whatever/whatever:99")


This seems fine, until you try to spin up a container, where it throws an exception (that you can catch, which is great).


dimage.withRun() { /* do nothing; just attempt to spin up container */ }


The problem is that takes some time on a loaded server, because it spins up a container for no real reason.

I would like a "validate" method. If that verb is too "heavy" and implies too much, "exists" would be fine, e.g.:


dimage = docker.image("whatever/whatever:99")

if (dimage.exists()) {
...
}

Workaround:



image_id = sh (script: "docker images -q whatever/whatever:99", returnStdout: true).trim()

if (image_id.isEmpty()) throw new Exception("Image not found")

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.