How to retrieve Node Tree when child value matches text
- 4 years ago
Thanks to some valuable contributions from other sites, I managed to find a solution. It was fairly easy in the end stiching some ideas from those posts. I have put it here in case anyone would like to make use of it.
import groovy.util.*
import java.text.SimpleDateFormatdef sdfDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss")
//Parse XML content in the response
def completedResponse = context.expand( '${ListCompletedStreams#Response}' )
def parsedcompletedResponse = new XmlSlurper().parseText(completedResponse)//Loop over each Job Entry
parsedcompletedResponse.jobs.jobEntry.each { jobEntry ->//Loop over every steo entry and pull out only those steps that fail. Find the parent Job Name and other parent properties.
jobEntry.steps.stepEntry.each { stepEntry ->
if (stepEntry.stepState.text() == "FAILED" ) {def strJobEntryRunDate = Date.parse("yyyy-MM-dd'T'HH:mm:ss", "${jobEntry.runDate.text()}")
log.info "\tJob Stream : ${jobEntry.name.text()} starting at " + sdfDateFormat.format(strJobEntryRunDate) + " has a failed Job Step."
log.info "\tJob Step: ${stepEntry.stepName.text()} failed after ${jobEntry.runDuration.text()} minutes."
}
}
}
return null