【问题标题】:Attempting to access file system from jenkinsfile尝试从 jenkinsfile 访问文件系统
【发布时间】:2018-01-13 23:35:48
【问题描述】:

我正在尝试使用 groovy 从 Jenkinsfile 访问文件系统。我正在遵循这个 SO 线程中的建议: Recursive listing of all files matching a certain filetype in Groovy

我已经给了访问权限

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

【问题讨论】:

    标签: jenkins groovy jenkins-pipeline


    【解决方案1】:

    最好使用findFiles 步骤,而不是Java API 来读取文件。这已被脚本安全列入白名单。

    each 循环由于 Jenkins 的 CPS 而无法在管道中工作。相反(如果您真的更喜欢它而不是旧的 for 循环),请将其包装在带有 @NonCPS 注释的方法中。

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      • 2010-11-24
      相关资源
      最近更新 更多