Issue
I am very new to using groovy. Especially when it comes to Jenkins+Groovy+Pipelines.
I have a string variable that can change from time to time and want to apply a regex to accomodate the 2 or 3 possible results the string may return.
r = "Some text that will always end in either running, stopped, starting."
def regex = ~/(.*)running(.*)/
assert regex.matches(r)
But I receive an error in the jenkins output:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.regex.Pattern.matches() is applicable for argument types: (java.lang.String)
UPDATE: I was able to create a pretty nifty jenking groovy while loop in a pipeline job i am creating to wait for a remote process using the regex info here and a tip in a different post (How do I iterate over all bytes in an inputStream using Groovy, given that it lacks a do-while statement?).
while({
def r = sh returnStdout: true, script: 'ssh "Insert your remote ssh command that returns text'
println "Process still running. Waiting on Stop"
println "Status returned: $r"
r =~ /running|starting|partial/
}());
Solution
Straight-forward would be:
String r = "Some text that will always end in either running, stopped, starting."
assert r =~ /(.*)running(.*)/
Answered By - injecteer
Answer Checked By - Gilberto Lyons (JavaFixing Admin)