Search code examples
regexjenkins-pipelinejenkins-email-ext

Need regex to included only specific lines from console output in email-ext plugin in jenkins pipeline


Need to include specific lines(some ID) from jenkins pipeline console output and send it using email-ext plugin. How I can write the regex for this. For Example:

Console ouput
published xyz
[servername] out: Built 123abcwxyabjd
few lines of o/p
[servername2] out: Built ewrewfdsfabcwxyabjd
again some o/p
[servername3] out: Built 1458543abcwxyabjd
published abc
some o/p
[servername2] out: Built dfds123abcwxyabjd
some o/p
[servername] out: Built dsfdsabcwxyabjd

What I need in o/p

published xyz
[servername] out: Built 123abcwxyabjd
[servername2] out: Built ewrewfdsfabcwxyabjd
[servername3] out: Built 1458543abcwxyabjd
published abc
[servername2] out: Built dfds123abcwxyabjd
[servername] out: Built dsfdsabcwxyabjd

one more is issue is that stages are in parallel i.e published xyz and published abc are in parallel and will output the ID's not in sequence

For me I'm able to get all the lines like

[servername] out: Built 123abcwxyabjd
[servername] out: Built 123abcwxyabjd



$(BUILD_LOG_REGEX, regex=".*(?=.*?Built).*?$

For me I'm able to get all the lines like

[servername] out: Built 123abcwxyabjd
[servername] out: Built 123abcwxyabjd

but not able to differentiate which is from which published stage. Even if I can select first three id and then publish text and then three id and then some text. May be it will be helpful.


Solution

  • Try

    ^(.* out: Built|published ).*$
    

    see https://regex101.com/r/CuAYph/2 There is also explanation on right