我正在尝试使用正则表达式模式匹配字符串。我收到以下错误:
ERROR: Build step failed with exception
groovy.lang.MissingMethodException: No signature of method:
Script1.$() is applicable for argument types: (Script1$_performCleanup_closure1) values: [Script1$_performCleanup_closure1@166d5b57]
Possible solutions: is(java.lang.Object), run(), run(), any(), use([Ljava.lang.Object;), any(groovy.lang.Closure) at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166) at
Script1.performCleanup(Script1.groovy:23) at Script1$performCleanup.callCurrent(Unknown Source) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174) at
Script1.run(Script1.groovy:76) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at
groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at
groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:
349) at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95) at
hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59) at
hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744) at
hudson.model.Build$BuildExecution.build(Build.java:206) at
hudson.model.Build$BuildExecution.doRun(Build.java:163) at
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504) at
hudson.model.Run.execute(Run.java:1810) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97) at
hudson.model.Executor.run(Executor.java:429)
我的代码是:
regex = /^(Build|Create|E2E|UTs|Cleanup).*_branch-113$|^Robots.*_branch-113-.*/
if (jobName ==~ ${regex}) {
println("Regex pattern: ${regex} matches with" + jobName)
} else {
println("Regex pattern: ${regex} does not matches with" + jobName)
}
在输出中:
我的正则表达式模式-- ^(Build | Create | E2E | UTs | Cleanup)。 _branch-113 $ | ^机器人。 _branch-113-。* < / strong>
我期望jobName和上述代码到jobName的输出像:
fail
pass
fail
pass
fail
pass
答案 0 :(得分:2)
我认为解决方案很简单,那就是删除${}
语句中的if
。像这样:
regex = /^(Build|Create|E2E|UTs|Cleanup).*_branch-113$|^Robots.*_branch-113-.*/
if (jobName ==~ regex) {
println("Regex pattern: ${regex} matches with" + jobName)
} else {
println("Regex pattern: ${regex} does not matches with" + jobName)
}