Jenkins 管道和 java.nio.file.* 方法的问题
Issue with Jenkins pipeline and java.nio.file.* methods
我正在尝试使用 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
}
}
这是管道脚本规范。它写在 tutorial 中。
readFile
step loads a text file from the workspace and returns its
content (do not try to use java.io.File
methods — these will refer to
files on the master where Jenkins is running, not in the current
workspace).
There is also a writeFile
step to save content to a text file in the
workspace
fileExists
step to check whether a file exists without loading it.
您可以在节点中使用这些 Jenkins 步骤,而不是如下所示的 java.io.File
或 java.nio.file.Files
。
String slavePath = 'C:\Something\only\on\slave\node'
String masterPath = 'D:\Something\only\on\master\node'
stage('One')
{
node ('slave')
{
bat returnStatus: true, script: 'set'
println fileExists(slavePath) // Should be true
println fileExists(masterPath) // Should be false
}
node ('master')
{
bat returnStatus: true, script: 'set'
println fileExists(slavePath) // false
println fileExists(masterPath) // true
}
}
我正在尝试使用 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
}
}
这是管道脚本规范。它写在 tutorial 中。
readFile
step loads a text file from the workspace and returns its content (do not try to usejava.io.File
methods — these will refer to files on the master where Jenkins is running, not in the current workspace).There is also a
writeFile
step to save content to a text file in the workspace
fileExists
step to check whether a file exists without loading it.
您可以在节点中使用这些 Jenkins 步骤,而不是如下所示的 java.io.File
或 java.nio.file.Files
。
String slavePath = 'C:\Something\only\on\slave\node'
String masterPath = 'D:\Something\only\on\master\node'
stage('One')
{
node ('slave')
{
bat returnStatus: true, script: 'set'
println fileExists(slavePath) // Should be true
println fileExists(masterPath) // Should be false
}
node ('master')
{
bat returnStatus: true, script: 'set'
println fileExists(slavePath) // false
println fileExists(masterPath) // true
}
}