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

archiveArtifacts and fileExists inconsistent in docker.inside() closure

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • docker-workflow-plugin
    • None
    • Jenkins 2.112
      Docker Pipeline 1.15, 1.17

      The following Pipeline code produces an error:

      def image = docker.image("any_existing_image_eg_alpine")
      image.inside {
          sh 'date > /tmp/test.txt'
          sh 'cat /tmp/test.txt' //works, shows file
      
          def fileContents = readFile '/tmp/test.txt' //works
          echo "Contents: ${fileContents}" //works, shows file
      
          echo "Exists: ${fileExists('/tmp/test.txt')}" //FAILS (returns false)
          archiveArtifacts '/tmp/*.txt' //FAILS the build
      }
      

      archiveArtifacts always reports that it matched no files (except in $WORKSPACE, see below).

      DSL steps in docker summary (what I've tried):

      • readFile(): works correctly on files in or out of $WORKSPACE
      • writeFile(): works correctly on files in or out of $WORKSPACE
      • fileExists(): works correctly only on files in $WORKSPACE (auto-mounted volume)
      • archiveArtifacts(): archives only files in $WORKSPACE  (auto-mounted volume) 

      So I guess there is a pattern ... and yet the behavior is inconsistent.  I could not find any documentation that explains what the rules are.

      UPDATE: readFile() now throws NoSuchFileException (docker-pipeline 1.17 and pipeline-basic-steps 2.7) for files outside the workspace, which is probably better.

       

       

          [JENKINS-51462] archiveArtifacts and fileExists inconsistent in docker.inside() closure

          Alexander Komarov created issue -
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/*' or '*' also match nothing.

          The interesting thing is that readFile works.

           
          New: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/\**' or '**' also match nothing.

          The interesting thing is that readFile works.

           
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/\**' or '**' also match nothing.

          The interesting thing is that readFile works.

           
          New: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          The interesting thing is that readFile works.  I've even tried using writeFile() to create the file, it made no difference.

           
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          The interesting thing is that readFile works.  I've even tried using writeFile() to create the file, it made no difference.

           
          New: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          The interesting thing is that readFile works.  I've even tried using writeFile() to create the file, it made no difference.

          Update: "fileExists" also fails in a container (returns false when file exists), even though readFile works.

           
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def container = docker.image("any_existing_image_eg_alpine")
          container.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          The interesting thing is that readFile works.  I've even tried using writeFile() to create the file, it made no difference.

          Update: "fileExists" also fails in a container (returns false when file exists), even though readFile works.

           
          New: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly
           * *writeFile()*: works correctly
           * *fileExists()*: incorrect (reports false when file exists)
           * *archiveArtifacts()*: (archives nothing while in inside() )

           
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly
           * *writeFile()*: works correctly
           * *fileExists()*: incorrect (reports false when file exists)
           * *archiveArtifacts()*: (archives nothing while in inside() )

           
          New: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly
           * *writeFile()*: works correctly
           * *fileExists()*: incorrect (reports false when file exists)
           * *archiveArtifacts()*: (archives only files under $WORKSPACE tree while in inside() (auto-mounted) )

           
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files.  It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing.

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly
           * *writeFile()*: works correctly
           * *fileExists()*: incorrect (reports false when file exists)
           * *archiveArtifacts()*: (archives only files under $WORKSPACE tree while in inside() (auto-mounted) )

           
          New: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          archiveArtifacts always reports that it matched no files (except in $WORKSPACE, see below).

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly on files in or out of $WORKSPACE
           * *writeFile()*: works correctly on files in or out of $WORKSPACE
           * *fileExists()*: works correctly only on files in $WORKSPACE (auto-mounted volume)
           * *archiveArtifacts()*: archives only files in $WORKSPACE  (auto-mounted volume) 

          So I guess there is a pattern ... and yet the behavior is inconsistent.  I could not find any documentation that explains what the rules are.

           
          Alexander Komarov made changes -
          Summary Original: archiveArtifacts not working inside() docker containers New: archiveArtifacts and fileExists not working inside() docker containers
          Alexander Komarov made changes -
          Summary Original: archiveArtifacts and fileExists not working inside() docker containers New: archiveArtifacts and fileExists inconsistent inside() docker containers
          Alexander Komarov made changes -
          Description Original: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              archiveArtifacts '/tmp/*.txt' //FAILS
          }
          {code}
          archiveArtifacts always reports that it matched no files (except in $WORKSPACE, see below).

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly on files in or out of $WORKSPACE
           * *writeFile()*: works correctly on files in or out of $WORKSPACE
           * *fileExists()*: works correctly only on files in $WORKSPACE (auto-mounted volume)
           * *archiveArtifacts()*: archives only files in $WORKSPACE  (auto-mounted volume) 

          So I guess there is a pattern ... and yet the behavior is inconsistent.  I could not find any documentation that explains what the rules are.

           
          New: The following Pipeline code produces an error:
          {code:java}
          def image = docker.image("any_existing_image_eg_alpine")
          image.inside {
              sh 'date > /tmp/test.txt'
              sh 'cat /tmp/test.txt' //works, shows file

              def fileContents = readFile '/tmp/test.txt' //works
              echo "Contents: ${fileContents}" //works, shows file

              echo "Exists: ${fileExists('/tmp/test.txt')}" //FAILS (returns false)
              archiveArtifacts '/tmp/*.txt' //FAILS the build
          }
          {code}
          archiveArtifacts always reports that it matched no files (except in $WORKSPACE, see below).

          DSL steps in docker summary (what I've tried):
           * *readFile()*: works correctly on files in or out of $WORKSPACE
           * *writeFile()*: works correctly on files in or out of $WORKSPACE
           * *fileExists()*: works correctly only on files in $WORKSPACE (auto-mounted volume)
           * *archiveArtifacts()*: archives only files in $WORKSPACE  (auto-mounted volume) 

          So I guess there is a pattern ... and yet the behavior is inconsistent.  I could not find any documentation that explains what the rules are.

           
          Alexander Komarov made changes -
          Summary Original: archiveArtifacts and fileExists inconsistent inside() docker containers New: archiveArtifacts and fileExists inconsistent in docker.inside() closure

            Unassigned Unassigned
            akom Alexander Komarov
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: