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

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/9f7a96a1-fc2d-41d7-ab31-1226555f224d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to