How to execute a Jenkins job until the build is green
This pipeline will run each day at 1 AM. It'll restart if the build fails.

pipeline {
    agent any

    triggers {
        cron('0 1 * * *')
    }

    stages {
        stage ('Build') {
            when {
                expression {
                    // When last build has failed
                    !hudson.model.Result.SUCCESS.equals(currentBuild.rawBuild.getPreviousBuild()?.getResult()) == true
                }
            }

            steps {
                sh "./myjob.sh"
            }

            post {
                failure {
                    // If the current job has failed, trigger it without
                    // waiting.
                    build job: "${JOB_NAME}", wait: false
                }
            }
        }
    }
}


If you want to wait before to re-trigger the job, you can add the option quietPeriod: (seconds) to the build step (https://jenkins.io/doc/pipeline/steps/pipeline-build-step/).

You might have to add these methods to the scriptApproval: