我正在尝试使用 java.nio.file.* 中的方法在 Jenkins 管道中执行一些基本的文件操作。无论代码存在于哪个节点块中,代码都在主节点上执行。在管道中,我已经验证了各种节点块是正确的——它们唯一地标识了特定的节点。但是,pathExists(以及其他移动、复制或删除文件的代码)总是在主节点上执行。任何想法发生了什么或如何解决它?
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
}
}