jenkinsci / jenkinsci/docker-workflow-plugin
[JENKINS-45152] Should be able to check if image exists
- 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
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
Assessment
This issue has not been assessed yet.