title: Jenkins pipeline, how to execute a sh from a script
body: <p>I need to run a <code>sh</code> to fetch the git tags from a Jenkins script.
  The sh is: </p>
  
  <pre><code>def tags = sh script: "git ls-remote --tags --refs ssh://git@bitbucket.xxx.git | cut -d'/' -f3", returnStdout: true
  </code></pre>
  
  <p>But it seems not to work. No idea why as Jenkins does not complain but <code>branchNames</code> is empty.
  Following what I'm trying to run:</p>
  
  <pre><code>ProjectUtils.addProperties([
      [$class: 'ParametersDefinitionProperty', 
          parameterDefinitions: [
              [$class: 'ExtensibleChoiceParameterDefinition',
                  name: 'INSTALLER_BRANCH', description: 'The set of installers to be deployed.',
                  editable: false,
                  choiceListProvider: [$class: 'SystemGroovyChoiceListProvider',
                      scriptText: '''
                          def branchNames = ['master']
                          def tags = sh script: "git ls-remote --tags --refs ssh://git@bitbucket.xxx.git | cut -d'/' -f3", returnStdout: true
                          for (tag in tags) {
                              branchNames.push(tag)
                          }
                          return branchNames
                      ''',
                      usePredefinedVariables: true
                  ]
              ]
          ]
      ]
  ])
  </code></pre>
  
  <p>I can call the <code>sh</code> before and it works:</p>
  
  <pre><code>stage ('installer') {
      println  "Checking Installer tags"
      def tags = sh(returnStdout: true, script: "git ls-remote --tags --refs ssh://git@bitbucket.xxx.git | cut -d'/' -f3")
      println  "Installer tags:"
      println  tags
  </code></pre>
  
  <p>but then I don't know how to pass the variable <code>tags</code> to the script <code>'''&lt;&gt;'''</code>.</p>
  
  <p>Any help would be appreciated.</p>