Discussion:
Executing a shell/python command in Jenkins Dynamic Choice Parameter Plugin
Robert Parker
2014-07-18 13:41:27 UTC
Permalink
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 pythonfrom 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?
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ioannis Moutsatsos
2014-07-19 02:23:07 UTC
Permalink
Given that dynamic UI controls such as Dynamic Parameter and Uno-Choice
<https://github.com/biouno/uno-choice-plugin> only support groovy, I think
it may be worthwhile investigating how groovy can be used to access
MongoDB.

To start with I would consider using the gmongo
<https://github.com/poiati/gmongo> wrapper to MongoDB.
Post by Robert Parker
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
#!/usr/bin/env pythonfrom 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?
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Parker
2014-07-21 17:12:42 UTC
Permalink
Do you have any examples of groovy script within a Dynamic Parameter
executing an external shell script? I can't seem to figure out the correct
syntax and then pass it back to jenkins in a way that will be parsed as a
set of parameter choices in the UI.

Thanks
Post by Ioannis Moutsatsos
Given that dynamic UI controls such as Dynamic Parameter and Uno-Choice
<https://github.com/biouno/uno-choice-plugin> only support groovy, I
think it may be worthwhile investigating how groovy can be used to access
MongoDB.
To start with I would consider using the gmongo
<https://github.com/poiati/gmongo> wrapper to MongoDB.
Post by Robert Parker
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
#!/usr/bin/env pythonfrom 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?
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Nothhard
2014-07-22 08:03:38 UTC
Permalink
Adapted from here
<http://stackoverflow.com/questions/159148/groovy-executing-shell-commands>.

//Create buffer to capture command's Standard Out
def sout = new StringBuffer(), serr = new StringBuffer()

//Define here the shell command you would like to execute
def proc = 'ls /'.execute()

//Capture command output into buffer
proc.consumeProcessOutput(sout, serr)

//Time to wait for command to complete
proc.waitForOrKill(1000)

//Converts command output to a list of choices, split by whitespace
return sout.tokenize()
Post by Robert Parker
Do you have any examples of groovy script within a Dynamic Parameter
executing an external shell script? I can't seem to figure out the correct
syntax and then pass it back to jenkins in a way that will be parsed as a
set of parameter choices in the UI.
Thanks
Post by Ioannis Moutsatsos
Given that dynamic UI controls such as Dynamic Parameter and Uno-Choice
<https://github.com/biouno/uno-choice-plugin> only support groovy, I
think it may be worthwhile investigating how groovy can be used to access
MongoDB.
To start with I would consider using the gmongo
<https://github.com/poiati/gmongo> wrapper to MongoDB.
Post by Robert Parker
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
#!/usr/bin/env pythonfrom 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?
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ivan Kalinin
2014-07-20 18:49:39 UTC
Permalink
Well, you can always try to fire a shell from the groovy script -- there
seems to be a way to access current executor.
Post by Robert Parker
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
#!/usr/bin/env pythonfrom 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?
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...