community.general.jenkins_script (8.5.0) — module

Executes a groovy script in the jenkins instance

Authors: James Hogarth (@hogarthj)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

The C(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.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Obtaining a list of plugins
  community.general.jenkins_script:
    script: 'println(Jenkins.instance.pluginManager.plugins)'
    user: admin
    password: admin
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Setting master using a variable to hold a more complicate script
  ansible.builtin.set_fact:
    setmaster_mode: |
        import jenkins.model.*
        instance = Jenkins.getInstance()
        instance.setMode(${jenkins_mode})
        instance.save()
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Use the variable as the script
  community.general.jenkins_script:
    script: "{{ setmaster_mode }}"
    args:
      jenkins_mode: Node.Mode.EXCLUSIVE
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Interacting with an untrusted HTTPS connection
  community.general.jenkins_script:
    script: "println(Jenkins.instance.pluginManager.plugins)"
    user: admin
    password: admin
    url: https://localhost
    validate_certs: false  # only do this when you trust the network!

Inputs

    
url:
    default: http://localhost:8080
    description:
    - The jenkins server to execute the script against. The default is a local jenkins
      instance that is not being proxied through a webserver.
    type: str

args:
    description:
    - 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).
    type: dict

user:
    description:
    - The username to connect to the jenkins server with.
    type: str

script:
    description:
    - The groovy script to be executed. This gets passed as a string Template if args
      is defined.
    required: true
    type: str

timeout:
    default: 10
    description:
    - The request timeout in seconds
    type: int

password:
    description:
    - The password to connect to the jenkins server with.
    type: str

validate_certs:
    default: true
    description:
    - If set to V(false), the SSL certificates will not be validated. This should only
      set to V(false) used on personally controlled sites using self-signed certificates
      as it avoids verifying the source site.
    type: bool

Outputs

output:
  description: Result of script
  returned: success
  sample: 'Result: true'
  type: str