ansible.builtin.jenkins_script (v2.9.27) — module

Executes a groovy script in the jenkins instance

| "added in version" 2.3 of ansible.builtin"

Authors: James Hogarth (@hogarthj)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

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
  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
  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
  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
  jenkins_script:
    script: "println(Jenkins.instance.pluginManager.plugins)"
    user: admin
    password: admin
    url: https://localhost
    validate_certs: no

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.

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).

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

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

timeout:
    default: 10
    description:
    - The request timeout in seconds
    version_added: '2.4'
    version_added_collection: ansible.builtin

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

validate_certs:
    default: 'yes'
    description:
    - If set to C(no), the SSL certificates will not be validated. This should only set
      to C(no) 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