简体   繁体   English

使用 groovy 匹配字符串的结尾

[英]Using groovy to match end of string

I'm using Jenkins and want to match all buildable jobs whose names end in _TEST but can't get it to match via regex.我正在使用 Jenkins 并希望匹配名称以_TEST但无法通过正则表达式匹配的所有可构建作业。

I have tried several ways but haven't been able to get it to match via groovy.我尝试了几种方法,但无法通过 groovy 使其匹配。

An equivalent, but far more concise solution than this one is一个等效但比这个更简洁的解决方案是

import hudson.model.*

def list = Hudson.instance
                 .items
                 .findAll { it.buildable && it.name.endsWith("_TEST") }
                 .collect { it.name }

I actually found a different way around my problem.我实际上找到了解决我的问题的不同方法。 Sorry, Monday mornings :)对不起,星期一早上:)

import hudson.model.*

def list = []

for (item in Hudson.instance.items.findAll()) {
  if (item.name.endsWith("_TEST")) {
    if (item.isBuildable()) {
      list.push(item.name)
    }
  }
}

return list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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