title: List git branches as dynamic parameter in declarative pipeline
body: <p>Im struggeling to include a dynamic choice parameter into my declarative pipeline. I have tried lots of different suggestions from everywhere which did not really help as I've completely lost track right now :-)</p>
  
  <p>For the desired functionality: I have a Jenkinsfile (declarative) for the jenkins pipeline. I want to have a parameter which allows me to choose a specific branch from a git repository to be used in the pipeline.</p>
  
  <p>Basic structure of the jenkinsfile:</p>
  
  <pre><code>pipeline {
  
      agent { node { label "XXX-XXX-XXX" } }
  
      options {
          gitLabConnection('XXX-XXX-XXX')
      }
  
      stages {
          stage("STAGE A") {
              parallel{
                  stage("A"){
                      steps {
                          // DO STUFF
                      }
                  }
                  stage("B"){
                      steps {             
                          // DO STUFF
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I've tried to add a parameter using the following snippet within the pipeline. I was not able to dynamically fill the list of choices. It was either empty or it generated errors.</p>
  
  <pre><code>parameters {
          choice(
              name: 'CHOICE_2',
              choices: 'choice_1\nchoice_2\nchoice_3\nchoice_4\nchoice_5\nchoice_6',
              description: 'CHOICE_2 description',
          )
  }
  </code></pre>
  
  <p>Alternatively I've tried to have the following outside of the pipeline declaration. I left one if the script variations in as an example. Here again, I was not able to populate the list of choices. The field stayed empty:</p>
  
  <pre><code>node {
      label "XXX-XXX-XXX"
      properties([
          parameters([
              [$class: 'ChoiceParameter', 
                  choiceType: 'PT_SINGLE_SELECT', 
                  description: 'The names', 
                  filterLength: 1, 
                  filterable: true, 
                  name: 'Name', 
                  randomName: 'choice-parameter-5631314439613978', 
                  script: [
                      $class: 'GroovyScript', 
                      script: [
                          classpath: [], 
                          sandbox: false, 
                          script: '''
                              def gettags = "git ls-remote git@XXX-XXX-XXX.git".execute()
                              def tagList = []
                              def t1 = []
                              String tagsString = null;
                              gettags.text.eachLine {tagList.add(it)}
                              for(i in tagList)
                                  t1.add(i.split()[1].replaceAll('\\^\\{\\}', ''))
                              t1 = t1.unique()
                              tagsString = StringUtils.join((String[])t1, ',');
  
                              return tagsString
                                  '''
                      ]
                  ]
              ], 
          ])
      ])
  }
  </code></pre>
  
  <p>At this point I've tried too many different approaches and would like to go a step back.</p>
  
  <p>Can anyone support me with an approach and some hints or ressources ?</p>
  
  <p>Thanks &amp; with best regards,</p>