Any option to enable "restart" for this "dynamic stage" creation pipeline?

I have this piece of the pipeline

def list
pipeline {
    agent {label 'it'}
    options {buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '1'))}
    stages {
        stage('Create List') {

            steps {
                script {
                    // you may create your list here, lets say reading from a file after checkout
                    list = ["Test-1", "Test-2", "Test-3", "Test-4", "Test-5"]
                }
            }
            post {
                cleanup {
                    cleanWs()
                }
            }
        }
        stage('Dynamic Stages') {
            
            steps {
                script {
                    for(int i=0; i < list.size(); i++) {
                        stage(list[i]){
                            echo "Element: $i"
                        }
                    }
                }
            }
            post {
                cleanup {
                    cleanWs()
                }
            }
        }
    }
}

And this shows, however, if we select stage name “Test-4”, its not allowing us to restart, only “Dynamic Stage” has option for restart. Is there any way to enable “Restart” ?

Same goes with this similar where below shows ability to dynamically create stages however option to. “Restart” dynamically created stages is not enabled. Appreciate if there is any other ideas?


        stage ('Create Model Stages dynamically...'){
            steps {
                script {
                    def build_properties = readProperties file: "file.txt"
                        build_properties.each{ k,v ->
                            image_properties[k]=v
                             stage ("Validate Model -  ${k}") {
                                 println "${v}"
                          }
                    }
                }
            }
        }

No, the stage restart feature is part of Declarative Pipeline, and while you may be using the top-level pipeline {…} structure the use of the script block shows that this is essentially Scripted, for which there is no direct equivalent. (At least not in Jenkins; CloudBees CI offers a checkpoint step which works in Scripted Pipeline and would support a dynamic stage list like the one you show.)

If you foresee the need to restart a stage and the reason to do so can be described mechanically, you would be better off just doing so automatically to begin with, normally using the retry step, optionally with conditions. (For complex cases you can directly use programming constructs like for loops and try-catch blocks, but then you lose some retry step magic like passing through explicit build aborts.)

You can also do retries directly in Bourne shell script or whatever is actually being run inside the stage. The same applies to the Pipeline timeout step vs. the Linux /usr/bin/timeout; it is better to use the platform native system where it would suffice. (Whereas the Pipeline steps could wrap around a larger block of Jenkins automation including allocation of an agent.)

Good day @jglick : yes we are using CloudBees CI, can you please share an example we can follow (yes, we do use “Retry” step) yet theres some use-cases that we want to restart manually.

Please share an example to use “CheckPoint” step available to cloudbees CI

Never mind @jglick : using checkpoint helps! Thank you so very much, first time heard about “checkpoint”