Q: How to pass input values to Scheduled Jenkins pipeline job? I have a Jenkins Pipeline which doesn't have any build parameter. But has input template inside. So, when a job is started using Build now, it gets triggered and waits for user input through Input Requested and the options are populated as choices.
This is working fine, when i run manually.
But, I want to enable default values for input choice variable, so that when a scheduled job starts, it will not wait for user input (through Input Requested) and continue to use default values.
My input template looks like this.
env.cluster_to_select = input(
                        id: 'cluster_to_select', message: 'Select a choice',
                        parameters: [
                                 choice(name: 'clusters',
                                       choices: env.list_files, //can take from populated string
                                       description: 'Based on cluster selection, nodes are shown'
                                        )
                        ]
                )

How to know if the job is triggered via scheduler and pass default values for input.

A: You can wrap the input in a timeout block, which itself should be in a try block. Then catch the exception, check whether it timed out or was aborted by a user, and proceed accordingly with the default parameters or abort the build.
env.cluster_to_select = try {
                            timeout(time: 120, unit: 'SECONDS') {
                                input(
                                    id: 'cluster_to_select', message: 'Select a choice',
                                    parameters: [
                                        choice(name: 'clusters',
                                            choices: env.list_files, //can take from populated string
                                            description: 'Based on cluster selection, nodes are shown'
                                            )
                                        ]
                                    )
                                }
                            }   catch(err) { // timeout reached or input aborted by user
                                def user = err.getCauses()[0].getUser()
                                if (user.toString() == 'SYSTEM') { // SYSTEM is timeout
                                    echo('Using default parameters')
                                } else {
                                    currentBuild.result = 'ABORTED'
                                    error("Pipeline aborted by: [${user}]")
                                }
                            }

See Pipeline: How to add an input step, with timeout, that continues if timeout is reached, using a default value.
