Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the following code snippet to populate the Active Choices Parameter when running a shell script from a Groovy Script in Jenkins:

job('my-job') {
  parameters {
    activeChoiceParam('paramName') {
      groovyScript {
        """
        def shellScriptOutput = sh(script: 'my-shell-script.sh', returnStdout: true).trim()
        return shellScriptOutput.tokenize('\\n')
        """
      }
    }
  }
}

In this code snippet, the activeChoiceParam parameter is used to define an Active Choices Parameter with the name paramName. The groovyScript block is used to execute a shell script called my-shell-script.sh and return its output as a list of choices for the Active Choices Parameter. The tokenize method is used to split the output by newline characters and return the resulting list of choices.

Note that this code snippet assumes that the sh method is available in the current context and that the shell script returns a list of choices separated by newline characters. If your shell script returns a different format or you need to customize the behavior of the sh method, you may need to modify this code accordingly.