简体   繁体   中英

AntBuilder (groovy) with comma separated files (FileSet "include")

I am using Groovy dsl in a Jenkins script where I am passing the "include" parameter value to Ant FileSet.

def ant = new AntBuilder()
def scanner = ant.fileScanner {     
  // grab ALL files requested to be run
  fileset(dir:"/jenkins/workspace/aJob") {
        def selectedFiles = params["testSuite"]
        include(name:"$selectedFiles")
  }
}

It works if params["testSuite"] is a single expression to select file, eg

**/tests/*.java

It fails (appears to me that Groovy is unable to understand that value as-is) to find the files if params["testSuite"] is specified as

**/tests/test1.java, **/tests/test1.java

However, to Ant, both the above values are correct.

Can someone tell me how I can make this work?

You're using the comma separated one in the wrong level. You're putting it in an <include> element instead of the includes attribute (see the doc page ).

So to use the comma method you'd do

def ant = new AntBuilder()
def scanner = ant.fileScanner {
  // grab ALL files requested to be run
  def selectedFiles = params["testSuite"]
  fileset(dir:"/jenkins/workspace/aJob", includes: "$selectedFiles")
}

And actually, you can use comma, space, or comma space (even though the doc doesn't mention that).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM