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

Issue with Jenkins pipeline and java.nio.file.* methods

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • pipeline
    • Jenkins 2.20 (plus earlier and later releases), Windows 2012 R2, slaves launched via Swarm plugin

      I am trying to use methods from java.nio.file.* to perform some basic file operations in a Jenkins pipeline. Regardless of the node block in which the code exists, the code executes on the master node. In the pipeline, I have verified that the various node blocks are correct--they uniquely identify specific nodes. However, pathExists (and other java.nio.file and java.nio.filesystem methods that move, copy or delete files) always executes on the master node. Any ideas what's happening or how to fix it?

      import java.nio.file.*
      
      String slavePath = 'C:\\Something\\only\\on\\slave\\node'
      String masterPath = 'D:\\Something\\only\\on\\master\\node'
      
      def pathExists (String pathName)
      {
          def myPath = new File(pathName)
          return (myPath.exists()) 
      }
      
      stage('One') 
      {
          node ('slave')
          {
              bat returnStatus: true, script: 'set'
              println (pathExists(slavePath))     // Should be true but is false.
              println (pathExists(masterPath))    // Should be false but is true.
          }
          node ('master')
          {
              bat returnStatus: true, script: 'set'
              println (pathExists(slavePath))     // false
              println (pathExists(masterPath))    // true
          }
      }
      

          [JENKINS-38662] Issue with Jenkins pipeline and java.nio.file.* methods

          Jesse Glick added a comment -

          Read the documentation. You may not use any file operations from Pipeline script.

          Jesse Glick added a comment - Read the documentation. You may not use any file operations from Pipeline script.

          Christoph Henrici added a comment - - edited

          jglick  Why exactly? (Apart from the master / node problematic)? 

          Jenkins is not alone in the world: Pipelines are bound to share data (files), which other Software, resp Processes.  And since readFile and writeFile "only" is supported for files with in the workspace of a Pipeline and are as such bound to a specific build, how does a humble  Jenkins user share application spaning data?

          BTW: the "shared" the is also not bound to be read-only

          Christoph Henrici added a comment - - edited jglick   Why exactly? (Apart from the master / node problematic)?  Jenkins is not alone in the world: Pipelines are bound to share data (files), which other Software, resp Processes.  And since readFile and writeFile "only" is supported for files with in the workspace of a Pipeline and are as such bound to a specific build, how does a humble  Jenkins user share application spaning data? BTW: the "shared" the is also not bound to be read-only

            Unassigned Unassigned
            gaccardo Glen Accardo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: