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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-06 14:30:17 +0000
Seen: 10 times
Last updated: May 06 '23
How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?
What is the process of serializing groovy traits using Gson?
What is the method to transform an XML hierarchical arrangement to CSV utilizing groovy?
How can Quartz be utilized in Grails?
How can you obtain the sha1 of the most recent commit in a git repository using C#?
How to modify the node label in Jenkins once the job has been completed successfully?
What are the typical approaches found in a Gradle build script?