Agent and docker container selection

Hello, who can show me a pipeline where I can select the node or agent and then choose a docker container of the selected agent, it must be updated each time you run the pipeline so that if you delete or create a new container the change is detected.

I have the following Pipeline but when I run it, the job waits for an input that is never shown at the time of building, what should I do to make the Pipeline work?

pipeline {
agent none

stages {
    stage('select container') {
        steps {
            script {
                def agentLabel = input(
                    id: 'agentLabel',
                    message: 'Select agent:',
                    parameters: [
                        [$class: 'ChoiceParameterDefinition',
                        choices: 'agent1\nagent2\nagent3',
                        description: '',
                        name: 'Agent']
                    ]
                )
                node(agentLabel) {
                    def dockerContainers = sh(script: 'docker ps --format "{{.ID}} - {{.Names}} - {{.Image}}"', returnStdout: true).trim()
                    def containerList = dockerContainers.split('\n')
                    def selectedContainer = input(
                        id: 'selectedContainer',
                        message: "Select container inside the node ${agentLabel}:",
                        parameters: [
                            [$class: 'ChoiceParameterDefinition',
                            choices: containerList.join('\n'),
                            description: '',
                            name: 'Container']
                        ]
                    )
                    echo "Selected container: ${selectedContainer}"
                }
            }
        }
    }
}

}


When running this pipeline it stays in processing state and never finishes, I understand that it waits for an input response to continue advancing but it does not appear to me in the pipeline construction to handle that parameter.

Thank you

@jcpedrique I’m not positive, because I don’t use declarative pipeline syntax. but I think the issue might be that you are trying to run scripted commands while not being on a node? Try something like this:

def agentLabel 
node(someDefaultNode) {
    agentLabel = input(
                    id: 'agentLabel',
                    message: 'Select agent:',
                    parameters: [
                        [$class: 'ChoiceParameterDefinition',
                        choices: 'agent1\nagent2\nagent3',
                        description: '',
                        name: 'Agent']
                    ]
                )
}

node(agentLabel) {
// some tasks
}