This should be possible with the API implemented in JENKINS-40997, closing.
If I'm missing something, please reopen, assign to me and describe what is missing for a proper solution (As always, pull requests welcome).