我正在编写用于过滤Jenkins控制台日志以进行Jenkins作业的Python脚本,并且我想用正则表达式搜索特定模式/文本。 下面是我要寻找的文字:在Jenkins控制台日志中查找特定文本的正则表达式
somename.SomeTest.testSomeName()
这是继段落或句子的一部分:
Failed to find the annotation and the status of the test public void
com.somename.qa.mobile.tests.somename.SomeTest.testSomeName().
The result is not deployed to Platform but we will proceed
with further tests.......
这样的句子以上存在于控制台日志超过20倍。我想查找 这个的每个实例并获得该方法名称somename.SomeTest.testSomeName()
。我曾尝试这个迄今\[([^\]]+)\] not deployed ([^ ]+)
和东西 缺少/不正确的,这个正则表达式
以下的部分是日志的小片段,我想找出每个以下test method name
所示 Failed to find the annotation....
句子:
21:18:19 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:170)
21:18:19 at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
21:18:19 at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92)
21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
21:18:26 2016-05-12 21:18:25.238 [ERROR] (1): Failed to find the annotation and the status of the test public void com.somename.qa.mobile.tests.somename.SomeTest.testSomeName(). The result is not deployed to Platform but we will proceed with further tests
21:18:26 somename.client.test.utilities.Platform.PlatformApiException: Platform API returned HTTP 400("Field :case_id is not a valid test case.")
21:18:26 at somename.client.test.utilities.platform.PlatformApiClient.sendRequest(PlatformApiClient.java:197)
21:18:26 at
以上只是一小段代码片段;设想在日志中出现以上片段超过20次。
嘿马辛,是我能够扫描每行,并使用正则表达式'输出。*( [^] + \(\))。*没有部署。*',我接近我想要的输出。我得到这个'com。somename.qa.mobile.tests.somename.SomeTest.testSomeName()'就像你刚才提到的那样。有没有一种方法可以摆脱最初的'com.somename.qa.mobile.tests.'部分(这是我的原始问题),只是打印'somename.SomeTest.testSomeName()'。这部分我想进一步删除将每次都是相同的。 –
当然,你可以把这个部分放在mateched表达式之前,例如。 '/com.somename.qa.mobile.tests.([^] + \(\))。* not deployed /' –