试图从jenkinsfile访问文件系统

试图从jenkinsfile访问文件系统,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,我正在尝试使用groovy从Jenkins文件访问文件系统。我遵循这条线索中的建议: 我已经允许访问 new java.io.File java.lang.String staticField groovy.io.FileType FILES 在脚本批准下 但是,此行失败,但未显示错误消息: new File('.').eachFileRecurse(FILES) { 下面是更广泛的代码块: stage("Install") { print "here a" new File('.

我正在尝试使用groovy从Jenkins文件访问文件系统。我遵循这条线索中的建议:

我已经允许访问

new java.io.File java.lang.String
staticField groovy.io.FileType FILES
在脚本批准下

但是,此行失败,但未显示错误消息:

new File('.').eachFileRecurse(FILES) {
下面是更广泛的代码块:

stage("Install") {
  print "here a"
  new File('.').eachFileRecurse(FILES) {
    print "here c"
    if(it.name.endsWith(".sh")) {
      print "here d"
      println it
    }
  }
  print "here b"
下面是该部分的控制台输出:

[Pipeline] stage
[Pipeline] { (Install)
[Pipeline] echo
here a
[Pipeline] }
[Pipeline] // stage
[Pipeline] echo
Email Recipients: opike99@gmail.com, opike@yahoo.com
[Pipeline] emailext
messageContentType = text/html; charset=UTF-8
Adding recipients from project recipient list
Adding recipients from trigger recipient list
Setting In-Reply-To since last build was not successful
最好使用步骤,而不是JavaAPI来读取文件。这被脚本安全性列为白名单

由于Jenkins的CPS,每个
循环都不能在管道中工作。相反(如果您真的喜欢它而不是好的旧式
for
循环),请将它包装在带有注释的方法中