I have a Jenkins job1 which triggers job2
stage("trigger job2") {
       steps {
           build job: job2,
                parameters: [
                    string(name: "test1", value: "test1"),
                    string(name: "test2", value: "test2"),
                ],
and job2 triggered and running, I need to know if job2's last stage fails; for example, in my case, the last stage is "RESULT". Now, if the RESULT stage on job2 is red/failed, return this one pass to job1 and in job1 stage trigger job2 should also display in red.
I tried these cases but they do not work.
Jenkins version is Jenkins 2.346.1
What I tried:
JOB1: modified
 def p = build job: job2, propagate: true,
                parameters: [
                    string(name: "test1", value: "test1"),
                    string(name: "test2", value: "test2"),
                ],
            script {
                    build.waitForCompletion()
            }
            if (p.result == 'FAILURE') {
                currentBuild.result = "FAILURE"
                error 'Job2 failed, marking Job1 as failed in the current stage'
                }
            }
Try 2:
JOB1 modified
def result = build.waitForCompletion()
            if (result.result == 'FAILURE') {
                currentBuild.result = "FAILURE"
                error 'Job2 failed, marking Job1 as failed in the current stage'
            }
I tried 3-4 different cases, but they didn't work, could someone advise me?