Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30533

Dockerfile ADD command is not getting well interpreted when using it on array format


      When using ADD instruction inside Dockerfile in a form of array parameter, the docker client is returning and error message, but that message is not being showed on the build console.

      The following instruction inside Dockerfile should copy a file to inside the image using the star wildcard:

      ADD ["target/myapp-*.tar.gz", "/usr/local/apps/"]

      When I build the image with docker official client (via command line "docker build .") it works just fine but when using the Create Image job it doest not create the image, the console output is:

      17:54:39 [Docker] INFO: Creating docker image from /var/lib/jenkins/jobs/app/workspace
      17:54:45 Step 0 : FROM java:7
      17:55:24 [Docker] INFO: Sucessfully created image myhub/app:master

      So I wrote a small script in order to run inside the Jenkins console and extract the result of the Create image build:

      import org.jenkinsci.plugins.dockerbuildstep.cmd.CreateImageCommand
      import org.jenkinsci.plugins.dockerbuildstep.DockerBuilder
      import javax.json.Json
      import javax.json.JsonObject
      def path = '/data/var/lib/jenkins/jobs/myapp/workspace/'
      def tag = 'myhub/myapp:master'
      def client = Jenkins.getInstance().getDescriptor(DockerBuilder.class).getDockerClient(null)
      def istream = client.buildImageCmd(new File(path)).withTag(tag).withNoCache(true).withRemove(true).exec()
      def streamReader = new BufferedReader(new InputStreamReader(istream, "UTF-8"))
      def inputStr
      while ((inputStr = streamReader.readLine()) != null) {
          def json = Json.createReader(new StringReader(inputStr)).readObject()
          println json

      And the output shows that the command is not being well interpreted as the docker client does:

      [stream:"Step 0 : FROM java:7\n"]
      [stream:" ---> 0ad6528abdca\n"]
      [stream:"Step 1 : RUN echo \"America/Sao_Paulo\" > /etc/timezone; dpkg-reconfigure -f noninteractive tzdata\n"]
      [stream:" ---> Running in da3b218202ec\n"]
      [stream:"\u001b[91m\nCurrent default time zone: 'America/Sao_Paulo'\n\u001b[0m"]
      [stream:"\u001b[91mLocal time is now:      Thu Sep 17 18:31:24 BRT 2015.\nUniversal Time is now:  Thu Sep 17 21:31:24 UTC 2015.\n\u001b[0m"]
      [stream:" ---> 05f2f338869a\n"]
      [stream:"Removing intermediate container da3b218202ec\n"]
      [stream:"Step 2 : ADD target/myapp*-all.tar.gz /usr/local/apps/\n"]
      [errorDetail:[message:"No source files were specified"], error:"No source files were specified"]

      Temporarily I rewrote my instruction to be just a plain command (not array format) in order to make it work, but I think that the plugin should be 100% compatible with docker instructions.

      The plugin should show the error message on the build console as well.

            vjuranek vjuranek
            tiagodeoliveira tiago oliveira
            0 Vote for this issue
            1 Start watching this issue