I am trying to match a string with regex pattern. I am receiving following error:
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)
My code is:
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)
}
In Output:
My regex pattern is of sort --- ^(Build|Create|E2E|UTs|Cleanup). _branch-113$|^Robots. _branch-113-.*
And I am expecting jobName and the output of the above code to the jobName to be like:
fail
pass
fail
pass
fail
pass
I think the solution is straight forward, that is remove the ${}
in the if
statement. Like this:
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)
}
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.