jenkins - 使用 eachFileRecurse 递归列出 Groovy 中的所有文件返回 FileNotFoundException
问题描述
我的new File
工作并包含任何 xml 文件,但我的但eachFileRecurse
返回java.io.FileNotFoundException
:
/home/jenkins/workspace/myjob/abcd/TestFlux
Caught: java.io.FileNotFoundException: /home/jenkins/workspace/myjob/abcd/TestFlux
java.io.FileNotFoundException: /home/jenkins/workspace/myjob/abcd/TestFlux
at tests_flux.foo(tests_flux.groovy:48)
at tests_flux$traiter.callCurrent(Unknown Source)
at tests_flux.run(tests_flux.groovy:114)
这是我在 Jenkins 上运行的代码:
导入静态 groovy.io.FileType.FILES
def foo() {
File f = new File("abcd/TestFlux")
String currentDir = f.getAbsolutePath()
println currentDir
f.eachFileRecurse(FILES) {
println it
}
}
解决方案
new File()
并不意味着文件存在或任何东西。它是一个持有人,被要求为您查看文件系统。例如
groovy:000> new File("/hehe/lol")
===> /hehe/lol
groovy:000> new File("/hehe/lol").exists()
===> false
groovy:000> new File("/hehe/lol").isDirectory()
===> false
推荐阅读
- forms - ProcessCmdKey 不适用于双显示器
- python - 如何通过在python中添加同一列的2个不同行值的值来估算特定的行值
- python - 遍历两个列表,将一个列表与另一个列表进行比较并返回值
- xcode - iphone v14.4.2 和 xcode 12 的 Xcode 构建失败
- 2d - 如何在 2D 游戏中停止正在减速的物体?
- json - 将 Spring Data 与 PostgreSQL JsonB 类型属性一起使用
- typescript - 打字稿中的条件类型
- excel - 自更新计算字段
- html - 如何在 CSS 中的圆形图像上使用 box-shadow?
- javascript - Node.js - eventListener - 如何在触发事件时登录文件