Reputation: 473
I'd like to create a Jenkins job where I do a backup and deploy of certain databases to a remote MongoDB instance. I'd like this build to be parameterized so that at build time the user chooses from a list of valid MongoDB hostnames and then once the user selects the valid DB hostname, a second list parameter choice box will be dynamically populated with all valid database names on that hostnames. Then once The user has selected the DB name, that will be stored in a parameter "DB" that can be passed to a Build Step "Execute Shell" script to do the actual work.
My problem is that I need for a way to execute a script in the Jenkins Dynamic Parameter (Cascading) Plug-in that will run a shell (or ideally, python) script that will return a list of valid DB names on the selected host. I'm not able to get groovy script portion of the plugin to execute shell commands on the local OS (like the"Execute Shell" build step does).
Ideally I'd like to run something like this where "MONGOHOST" is the first parameter chosen by the user:
#!/usr/bin/env python
from pymongo import MongoClient
client = MongoClient('mongodb://${MONGOHOST}:27017/')
choicelist = client.database_names()
client.close()
I'd then like "choicelist" to be presented in such a way as they become populated as the available choices for a "DB" parameter.
How can I achieve this, especially since the Dynamic Choice parameter only accepts groovy script and not native python?
Upvotes: 7
Views: 2980
Reputation: 170698
Usually the dynamic parameter plugin just loads the options from simple ini files. So, if you want to update the list of available options, you just have to update these files on the Jenkins instance.
BTW, If you are trying to implement a self-service portal, you may want to have a look at RunDeck, which I discovered recently and it seems considerably more user-friendly than Jenkins.
Upvotes: -1