jenkins_script - Executes a groovy script in the jenkins instance
New in version 2.3.
Synopsis
- The
jenkins_script
module takes a script plus a dict of values to use within the script and returns the result of the script being run.
Options
parameter | required | default | choices | comments |
---|---|---|---|---|
args |
no |
A dict of key-value pairs used in formatting the script using string.Template (see https://docs.python.org/2/library/string.html#template-strings).
|
||
password |
no |
The password to connect to the jenkins server with.
|
||
script |
yes |
The groovy script to be executed. This gets passed as a string Template if args is defined.
|
||
timeout
(added in 2.4)
|
no | 10 |
The request timeout in seconds
|
|
url |
no | http://localhost:8080 |
The jenkins server to execute the script against. The default is a local jenkins instance that is not being proxied through a webserver.
|
|
user |
no |
The username to connect to the jenkins server with.
|
||
validate_certs |
no | True |
If set to
no , the SSL certificates will not be validated. This should only set to
no used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
|
Examples
- name: Obtaining a list of plugins jenkins_script: script: 'println(Jenkins.instance.pluginManager.plugins)' user: admin password: admin - name: Setting master using a variable to hold a more complicate script vars: setmaster_mode: | import jenkins.model.* instance = Jenkins.getInstance() instance.setMode(${jenkins_mode}) instance.save() - name: use the variable as the script jenkins_script: script: "{{ setmaster_mode }}" args: jenkins_mode: Node.Mode.EXCLUSIVE - name: interacting with an untrusted HTTPS connection jenkins_script: script: "println(Jenkins.instance.pluginManager.plugins)" user: admin password: admin url: https://localhost validate_certs: no
Return Values
Common return values are documented here Return Values, the following are the fields unique to this module:
name | description | returned | type | sample |
---|---|---|---|---|
output |
Result of script
|
success | string | Result: true |
Notes
Note
- Since the script can do anything this does not report on changes. Knowing the script is being run it’s important to set changed_when for the ansible output to be clear on any alterations made.
Status
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/jenkins_script_module.html