[英]Regex for extracting build number from Copy artifacts plugin in Jenkins
I have a Jenkins build that copies an artifact from another build. 我有一个Jenkins构建,它从另一个构建中复制一个工件。
Using description setter plugin I want to extract the build number from which I take the artifact. 使用description setter插件我想提取我从中获取工件的构建号。
The log file contains this line : 日志文件包含以下行:
Copied 1 artifact from "Mybuild" build number 569
I need to use regex to extract only the integer 569
(can be any int). 我需要使用正则表达式只提取整数569
(可以是任何int)。 Also the 1
can be any int and Mybuild
can be any string (but no spaces, one word). 1
也可以是任何int, Mybuild
可以是任何字符串(但没有空格,一个字)。 I can assume the words Copied, artifact, from, build, number
are constant and always appear 我可以假设单词Copied, artifact, from, build, number
是常量并且总是出现
I have tried to match a regex, but with no luck. 我试图匹配正则表达式,但没有运气。 Also tried some regex generator websites but no luck either. 还尝试了一些正则表达式生成器网站,但也没有运气。
Thanks. 谢谢。
You could probably use 你可以使用
Copied (\d+) artifact from "([^"]+)" build number (\d+)
and then use the third group (or remove the parentheses around the first two captured tokens and use group number 1). 然后使用第三组(或删除前两个捕获的令牌周围的括号并使用组号1)。
\\d
refers to any decimal digit, the +
trailing it is a so-called quantifier that will try matching the previous token (the digit in this case) at least one times and as often as possible. \\d
指任何十进制数字, +
尾随它是一个所谓的量词 ,它将尝试匹配前一个令牌(在这种情况下为数字)至少一次并且尽可能频繁地匹配。 [^"]
is a character class containing any character that is not a double quote. This way we can make sure that we catch everything within the quotes (not strictly necessary here, but a good pattern to keep in mind). All the rest is just matched verbatim. [^"]
是一个包含任何不是双引号的字符的字符类。这样我们可以确保我们捕获引号内的所有内容(这里不是绝对必要的,但要记住一个好的模式)。其余所有只是逐字匹配。
Quick PowerShell test: 快速PowerShell测试:
PS> 'Copied 1 artifact from "Mybuild" build number 569' -match 'Copied (\d+) artifact from "([^"]+)" build number (\d+)'
True
PS> $Matches
Name Value
---- -----
3 569
2 Mybuild
1 1
0 Copied 1 artifact from "Mybuild" build number 569
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.