简体   繁体   English

如何从jenkins控制台使用groovy脚本捕获第二个字符串

[英]How to capture second string using groovy script from jenkins console

I need to configure rspec test case run count on a jenkins job. 我需要在jenkins作业上配置rspec测试用例的运行次数。 Below is the format of the entry in the jenkin console after test run. 以下是测试运行后jenkin控制台中条目的格式。

3 examples, 0 failures

 6 examples, 0 failures

We have such entry twice in console as shown above (because of 2 ruby script run). 如上图所示,我们在控制台中有两次这样的输入(因为运行了2个ruby脚本)。 So after all the runs, when build is done, I need to capture both the entry and display at the job shown at Build History in jenkins. 因此,在所有运行之后,完成构建后,我需要捕获条目并在jenkins的“构建历史”中显示的工作中显示。

So to capture the above count now I am using below groovy script at groovy Postbuild of jenkin configuration. 因此,现在要捕获以上计数,我在詹金配置的groovy Postbuild中使用以下groovy脚本。 But it picks just the first match of the string from the jenkins console: 但是它只是从jenkins控制台中选择字符串的第一个匹配项:

    matcher = manager.getLogMatcher("(.*) examples, (.*) failures")
if(matcher != null && matcher.matches()) {
    totalTests = matcher.group(1)
    failedTests = matcher.group(2)
    description += "<br/>UI Tests: total: ${totalTests}, Fail: ${failedTests}"
}

How do I do to get 2, 3rd match of entry from jenkins console: 我要如何从jenkins控制台中获得2、3rd匹配项:

You can also try with build.getLog(int maximumLines), and then parse the output with regex. 您也可以尝试使用build.getLog(int maximumLines),然后使用正则表达式解析输出。 For example: 例如:

def buildLog = manager.build.getLog(10) // you might need to change the amount of maximum lines
def group = (buildLog =~ /(\d+) examples, (\d+) failures/ )
for(int i=0; i<group.size();i++) {
    manager.createSummary("info.gif").appendText("examples: ${group[i][1]}, failures: ${group[i][2]}", false)
}

in this case, the results would be added to the each build info. 在这种情况下,结果将添加到每个构建信息中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Groovy 控制台脚本/Jenkins API 从每个 Jenkins 作业获取脚本路径 - How to get Script Path from each Jenkins Jobs using Groovy Console Script/Jenkins API Groovy 脚本到 Grep 来自 jenkins 控制台 Z78E6221F6393D1356Z681DB398F14CED6 的字符串 - Groovy script to Grep a string from jenkins console output 如何在Jenkins奴隶的脚本控制台中使用groovy运行python命令? - How to run python commands using groovy in Jenkins slaves' Script Console? 如何使用 bash 从 groovy 脚本控制台 (Jenkins) 向 python 发送单个流水线命令? - How to send a single pipelined command to python using bash from a groovy script console (Jenkins)? 使用Jenkins脚本控制台并查看Groovy输出 - Using Jenkins script console and seeing the Groovy output 如何使用 groovy 脚本替换 jenkins 管道中的字符串 - How to replace string in jenkins pipeline using groovy script 如何使用在脚本控制台上运行的Groovy脚本自动执行Jenkins任务 - How to automate a Jenkins task using groovy script which runs on script console 从 Jenkins Groovy Script-Console 编写文件 - Write a File from Jenkins Groovy Script-Console 如何使用groovy脚本控制台杀死Jenkins工作中止后留下的进程? - How do i kill a process left behind after an aborted Jenkins job, using the groovy script console? 如何使用groovy脚本订购Jenkins参数 - How to order Jenkins Parameters using groovy script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM