Jenkins日志解析器插件在jenkins控制台
中找到低于字符串时使作业不稳定以下两个正则表达式来自一个文件。它告诉它是否发现“未知命令”或“警告”将其视为警告。
warning /unknown command/
warning /(?i)\bwarning\b/i
如果在下面的上下文中找到“unknown command”和WARNING,如何忽略。在组合中
[exec] ORA-0042: unknown command ")" - rest of line ignored.
[deployComposite] WARNING: Error in applying config plan: Namespace prefix 'ui' used but not declared.. Config plan was skipped.
请帮助两个不同的正则表达式。
还有一个可以用来从
获得帮助的正则表达式工具提前致谢
答案 0 :(得分:1)
要匹配多行,您需要
unknown command
\n
,即跳到下一行WARNING
时使用否定前瞻来拒绝匹配正则表达式
.*unknown command[^\n]*\n(?![^\n]*WARNING)
这里有一些Java代码,包括用于演示的示例输入:
String value = "[exec] ORA-0042: unknown command \")\" - rest of line ignored.\n"
+ "[deployComposite] WARNING: Error in applying config plan: Namespace prefix "
+ "'ui' used but not declared.. Config plan was skipped.";
Pattern pattern = Pattern.compile(".*unknown command[^\n]*\n(?![^\n]*WARNING)");
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
System.out.println("Matched: " + matcher.group(0));
} else {
System.out.println("No match!");
}
这将输出:
No match!
如果您现在将字符串WARNING
更改为DEBUG
,则输出将为:
Matched: [exec] ORA-0042: unknown command ")" - rest of line ignored.