小编典典

FileNameFinder()。getFileNames在一个Jenkins节点上失败

jenkins

使用groovy从jenkins工作空间获取文件列表在一个节点上失败,但在另一个节点上有效。这是管道中的代码:

 def pd = pwd()
 bat "dir $pd"
 def bat_files = new FileNameFinder().getFileNames(pd, 'G*.bat')

输出:

C:\Jenkins\Slave\workspace\TestFolder\CodeTestPipe>dir C:\Jenkins\Slave\workspace\TestFolder\CodeTestPipe 
 Volume in drive C is OSDisk
 Volume Serial Number is AAA1-73FA

 Directory of C:\Jenkins\Slave\workspace\TestFolder\CodeTestPipe

01/23/2017  05:34 PM    <DIR>          .
01/23/2017  05:34 PM    <DIR>          ..
01/23/2017  05:34 PM                 4 GOL.bat
               1 File(s)              4 bytes
               2 Dir(s)  134,906,617,856 bytes free
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
C:\Jenkins\Slave\workspace\TestFolder\CodeTestPipe does not exist.
    at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:483)
    at org.codehaus.groovy.ant.FileIterator.setNextObject(FileIterator.java:119)
    at org.codehaus.groovy.ant.FileIterator.hasNext(FileIterator.java:81)
    at groovy.util.FileNameFinder.getFileNames(FileNameFinder.groovy:44)
    at groovy.util.FileNameFinder$getFileNames.callCurrent(Unknown Source)
    at groovy.util.FileNameFinder.getFileNames(FileNameFinder.groovy:31)
    at

阅读 328

收藏
2020-07-25

共1个答案

小编典典

管道在Jenkins主服务器上执行,只有通过启用了远程处理的API的魔力,事情才会在所选节点上发生。因此File以及所有使用File的东西都不起作用,而且永远不会:它总是在master上执行。

来源:https//groups.google.com/forum/#!topic /
jenkinsci- users /
yBiYbwWjg-I

我能够通过在bat命令中使用dir获取文件:

def bat_out = bat( returnStdout: true, script: '@echo off & dir /b G*.bat').trim()
2020-07-25