'Jenkins "Git Parameter" plugin with "useRepository" option

I'm using "Git Parameter" plugin to allow users to pick branch\tag for configured repositories.

This plugin has "useRepository" option to allow linking with the configured repos in the "Pipeline script from SCM" option:

enter image description here

This assumes that i need to preconfigure some repos in the Jenkins pipeline (in the Jenkins UI) to be able to use "Git Parameter" plugin in the pipelines.

But i want to dynamically predefine list of repos from the pipeline code itself, without any configuration in the "Pipeline script from SCM" section. Unfortunately this doesn't work.

I'm tried to add "checkout" block with "GitSCM" class before calling "gitParameter" but with no success.

Code example:

def app_components = [
    BACKEND        : ["NAME": "backend", "GIT": "ssh://[email protected]/_git/backend"],
    FRONTEND       : ["NAME": "frontend", "GIT": "ssh://[email protected]/_git/fronend"]
]
pipeline {
    agent any
 
    stages {
        stage('Test') {
            steps {
                script {
                    dynamicParameters = []
                    app_components.eachWithIndex { name, components, index ->
                        checkout([
                            $class: 'GitSCM',
                            branches: [[name: '*/master']],
                            doGenerateSubmoduleConfigurations: false,
                            extensions: [[$class: 'CleanCheckout']],
                            submoduleCfg: [],
                            userRemoteConfigs: [[credentialsId: 'XXX', url: components.GIT]]
                        ])
                        dynamicParameters << gitParameter(name: 'BRANCH_' + name, defaultValue: 'develop', quickFilterEnabled: true, type: 'PT_BRANCH_TAG', listSize: '10', useRepository: components.GIT)
                    }
                   
                    def userInput = input(
                     id: 'userInput', message: 'Test message:?',
                     parameters: dynamicParameters
                    )
                    println(userInput);
                   
                }
            }
        }
    }

Git parameters text fields are always empty:

enter image description here

Could you advice some solution in this scenario?



Solution 1:[1]

Play around with adding

gitParameter branchFilter: 'origin/(.*)',

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney