I am trying to find solution for parsing logs from jenkins console and add matched logs into email body and send it via emailext.
I have following log lines in my console. I need to extract all matching lines and add in message body
OPERATION=backup|ENV_NAME=http://example.com:8091|EVENT=backup|START_TIME=2022-11-10 09:20:28.897461|END_TIME=2022-11-10 09:20:30.824839|RESULT=SUCCESS
I have similar log lines on console. all of them will have one common key-value that is "OPERATION=backup" and all the keys . I need to extract all lines having "OPERATION=backup|"
I have tried following but unable to parse it and add in message body .
success {
script {
def operations = manager.getLogMatcher ("(.*)OPERATION=backup(.*)")
}
emailext attachLog: false, mimeType: 'text/plain', subject: "DB backup for '${envNameAlias}' having build #${currentBuild.number}: ${currentBuild.currentResult}",
body: "Job completed..\nSee logs for more info:\n${env.BUILD_URL}/console",
to: 'abc.xyz@ey.org'
}
I am unclear about the steps forward. Please help with some inputs.
While going through belly of stackoverflow for solution, i found many solutions working with groovy post-build plugin, which is not installed in our organisation's jenkins.
solution :
tried following, works partially, i am getting almost whole log now in email then just few lines
success {
emailext attachLog: false, mimeType: 'text/plain', attachmentsPattern: '*', subject: "Couchbase export for build #${currentBuild.number}: ${currentBuild.currentResult}",
to: 'abc.xyz@ey.org',
body: """Job completed..\nSee logs for more info:\n ${env.BUILD_URL}/console \n \n \${BUILD_LOG_REGEX, regex="OPERATION=backup|", linesBefore=0, linesAfter=5, maxMatches=5, showTruncatedLines=false, escapeHtml=true} , regards Jenkins"""
}