Skip to content

Commit

Permalink
[FIXED JENKINS-34276] Allow Image.inside to run with either a local o…
Browse files Browse the repository at this point in the history
…r registry-prefixed name.
  • Loading branch information
jglick committed Dec 8, 2016
1 parent 46432bb commit 417acf3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
27 changes: 27 additions & 0 deletions demo/JENKINS_HOME/jobs/puller/config.xml
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.9">
<actions/>
<description>JENKINS-34276 verification; run after docker-workflow #1</description>
<keepDependencies>false</keepDependencies>
<properties>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers/>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.23">
<script>node {
echo 'Start with an empty local cache:'
sh &apos;(docker images -q examplecorp/spring-petclinic; docker images -q localhost/examplecorp/spring-petclinic) | xargs docker rmi --no-prune=true --force || :&apos;
docker.withRegistry(&apos;https://localhost/&apos;, &apos;docker-registry-login&apos;) {
echo 'Missing initially, should pull and get latest tag:'
docker.image(&apos;examplecorp/spring-petclinic&apos;).inside {
sh &apos;ls -l /tomcat7/webapps/petclinic.war&apos;
}
echo 'This time it should be in local cache and not need to pull:'
docker.image(&apos;examplecorp/spring-petclinic&apos;).inside {}
}
}</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
</flow-definition>
2 changes: 1 addition & 1 deletion demo/plugins.txt
@@ -1,5 +1,5 @@
org.jenkins-ci.plugins:authentication-tokens:1.3
org.jenkins-ci.plugins:docker-commons:1.5
org.jenkins-ci.plugins:docker-workflow:1.9
org.jenkins-ci.plugins:docker-workflow:1.10-SNAPSHOT
org.jenkins-ci.plugins.icon-shim:icon-shim:2.0.3
org.jenkins-ci.plugins:xvnc:1.24
Expand Up @@ -114,12 +114,18 @@ class Docker implements Serializable {

public <V> V inside(String args = '', Closure<V> body) {
docker.node {
if (docker.script.sh(script: "docker inspect -f . ${id}", returnStatus: true) != 0) {
// Not yet present locally.
// withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
pull()
def toRun = imageName()
if (toRun != id && docker.script.sh(script: "docker inspect -f . ${id}", returnStatus: true) == 0) {
// Can run it without registry prefix, because it was locally built.
toRun = id
} else {
if (docker.script.sh(script: "docker inspect -f . ${toRun}", returnStatus: true) != 0) {
// Not yet present locally.
// withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
pull()
}
}
docker.script.withDockerContainer(image: id, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
docker.script.withDockerContainer(image: toRun, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
body()
}
}
Expand Down

0 comments on commit 417acf3

Please sign in to comment.