I am trying to use methods from java.nio.file. * to perform some basic file operations in the Jenkins pipeline. Regardless of the node block in which the code exists, the code runs on the main node. In the pipeline, I checked that the various node blocks are correct - they uniquely identify certain nodes. However, pathExists (and other code that moves, copies, or deletes files) are always executed on the main node. Any ideas what is 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 } }
source share