jenkins_script – Executes a groovy script in the jenkins instance¶
Synopsis¶
- The jenkins_scriptmodule takes a script plus a dict of values to use within the script and returns the result of the script being run.
Parameters¶
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.
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
  set_fact:
    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, the following are the fields unique to this module:
| Key | Returned | Description | 
|---|---|---|
| output 
                  string
                                       | success | Result of script Sample: Result: true | 
Status¶
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Authors¶
- James Hogarth (@hogarthj)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.
