[Declarative Pipeline] Using Dockerfile not in root of checkout

156 views
Skip to first unread message

Staffan Forsell

unread,
Feb 5, 2017, 2:50:16 PM2/5/17
to Jenkins Users
I have an normal pipeline that looks like this:

#!groovy
node('docker_host') {
  stage("checkout") {
    p4sync credential: 'superSecretCred', depotPath: '//path'
  }
  def myEnv
  stage("docker build") {
    myEnv = docker.build("mytag", "utils/docker")
  }
  myEnv.inside {
    stage("build") {
      sh "./gradle"
    }
    } 
}

It builds a docker image and run the build stage in this image. The only non-standard stuff is that the Dockerfile is not in the root but in the "utils/docker" subdir to reduce the build context for docker.
I'm trying to convert this to a declarative pipeline but I can't find a way to get it to accept the Dockerfile in a separate dir. Normally this is done by adding the "utils/build" at the end of the docker build command.
My converted attempt looks like this:

pipeline {
  agent {
    label "docker_host"
  }
  stages {
    stage("Checkout") {
      steps {
        p4sync credential: 'superSecretCred', depotPath: '//path'
      }
    }
    stage("Echo world") {
      agent {
        dockerfile {
          label "docker_host"
          args "utils/docker"
          // dockerfile "utils/docker/Dockerfile"
        }
      }
      steps {
        sh "./gradle"
      }
    }
  }
}

This fails with 
java.io.IOException: java.io.FileNotFoundException: /jenkins/workspace/test-job-declarative@2/Dockerfile (No such file or directory)
at hudson.remoting.FastPipedInputStream.read(FastPipedInputStream.java:169)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2001)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1980)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1957)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1907)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:778)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:803)
at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:89)
at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:81)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: /jenkins/workspace/test-job-declarative@2/Dockerfile (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at hudson.FilePath$33.invoke(FilePath.java:1789)
at hudson.FilePath$33.invoke(FilePath.java:1782)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2772)
at hudson.remoting.UserRequest.perform(UserRequest.java:153)
at hudson.remoting.UserRequest.perform(UserRequest.java:50)
at hudson.remoting.Request$2.run(Request.java:332)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
... 1 more

Using the dockerfile closure, it's unclear if args is for the build command or the subsequent run command (my guess is the latter).
Anybody know a way to use a Dockerfile that's not in the root? Or is it not supported (yet)?

/Thanks Staffan

Staffan Forsell

unread,
Feb 5, 2017, 3:01:45 PM2/5/17
to Jenkins Users
Hmmm, of course I found https://issues.jenkins-ci.org/browse/JENKINS-41668 a couple of minutes later...

Andrew Bayer

unread,
Feb 6, 2017, 6:57:56 AM2/6/17
to jenkins...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/78dea921-bc15-4e4f-8662-209f4aa80e86%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Staffan Forsell

unread,
Feb 7, 2017, 5:35:18 PM2/7/17
to Jenkins Users
Ok, thx. I will test it as soon as it's merged/released.
/S
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages