【发布时间】:2016-12-21 14:08:37
【问题描述】:
我对使用 groovy 很陌生。尤其是 Jenkins+Groovy+Pipelines。
我有一个可以不时更改的字符串变量,我想应用一个正则表达式来适应字符串可能返回的 2 或 3 个可能的结果。
在我的 groovy 代码中:
r = "Some text that will always end in either running, stopped, starting."
def regex = ~/(.*)running(.*)/
assert regex.matches(r)
但我在 jenkins 输出中收到错误:
hudson.remoting.ProxyException:groovy.lang.MissingMethodException:没有方法签名:java.util.regex.Pattern.matches() 适用于参数类型:(java.lang.String)
更新: 我能够在我正在创建的管道作业中创建一个非常漂亮的 jenking groovy while 循环,以使用此处的正则表达式信息和不同帖子 (do .. while() in Groovy with inputStream?) 中的提示等待远程进程。
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/
}());
【问题讨论】:
-
我最终取出了 'assert' 行,只是做 'r =~ /running|starting|stopped/' 感谢@injecteer