Issue
In Jenkins' Groovy, how can I detect that some other build is waiting for user input, as triggered by statements like input message: 'Retry?' ok: 'Restart'
?
I checked the Executor and Build API docus, but couldn't identify something that matches. executor.isParking()
sounded promising, but returns false.
Solution
The problem with Florian's answer is that if the input is waiting for a while, possibly across restarts of Jenkins, it might not be the last line in the log.
This is better:
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction
def jobs = Jenkins.instance.getAllItems(WorkflowJob.class)
jobs.each { job ->
job.builds.each { build ->
if (build.isBuilding() && build.actions.last() instanceof InputAction) {
println "$job.fullName #$build.number"
}
}
}
This one is looking specifically for WorkflowJob
jobs but you could change the class to be FreeStyleProject
or whatever other kind of thing you want to look for. But checking that the last action is input seems like a good way to know if it's waiting for input.
Answered By - ZombieDev
Answer Checked By - Clifford M. (JavaFixing Volunteer)