我想删除以AAA开头的Jenkins作业列表(例如)
当我用显式字符串做它时它工作正常
if (item.name ==~ /AAA.*/){ item.delete() }
但是当我试图从Jenkins Build属性中获取正则表达式时,我失败了并且没有调用if ...
import hudson.model.* import hudson.node_monitors.* import hudson.slaves.* import java.util.concurrent.* jenkins = Hudson.instance def thr = Thread.currentThread() def build = thr?.executable String REGEX = build.environment.get("Include_Regex") println "REGEX is " + REGEX for (item in jenkins.items){ println("\t ${item.name}"); println("\t ${item.name.getClass()}"); if (item.name ==~ REGEX){ item.delete() println("TEST"); } }
当我运行它时,我得到所有作业的列表:在工作区中构建/ var/lib/jenkins/jobs/Bulk_Delete_Job/workspace
REGEX is /AAA.*/ AAA_test_1 class java.lang.String AAA_test_2 class java.lang.String AAA_test_3 class java.lang.String Bulk_Delete_Job class java.lang.String ConfiguredJob class java.lang.String JobZ class java.lang.String TEST_SCM class java.lang.String
但没有删除/没有打印"TEST" - > if if never true true ....
需要帮助,谢谢!
String不应包含斜杠 - 使用AAA.*而不是/AAA.*/.