How to use getJobsGraph method in Pipeline script

Hello,
Is there any way to use getJobsGraph() method and than vertexSet() in Pipeline Script?. I’m now rewrite my old code from dsl files which where used in Build Flow plugin recently. I need to upgrade my Jenkins to 2.289.2 This is why I need to stop using Build Flow Plugin and start with Pipeline plugin.
I have loop like this:
for (item in build.getJobsGraph().vertexSet())
{
if (item.getBuild().getNextBuild() == null)
{
if (item.getBuild().getResult() != SUCCESS)
{
build.state.setResult(FAILURE)
}
}
}
It must be translate to syntax understandable for Pipeline plugin.
Thanks for all yours answer

Uh. I’m trying to figure out what its trying to do to make a guess at what you should replace it with.

Is it just looping through all jobs until it finds the last one, then sets the current one to that status?

If so it’s a pretty obscure scenario and I’d like to know more about it’s purpose