FileNameFinder().getFileNames在一个Jenkins节点上失败 [英] FileNameFinder().getFileNames fails on one Jenkins node

查看:173
本文介绍了FileNameFinder().getFileNames在一个Jenkins节点上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Getting a list of files from jenkins workspace using groovy fails on one node but it works on another. Here is the code in the pipeline:

 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

推荐答案

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

Pipelines are executed on the Jenkins master, and only through the magic of remoting-enabled APIs do things happen on the selected node. So File, and everything using File, doesn't work, and never will: It always executes on master.

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

我能够通过bat命令中的dir获取文件:

I was able to get the files by using the dir in bat command:

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

这篇关于FileNameFinder().getFileNames在一个Jenkins节点上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆