�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
Z
d d l m Z d d
l
m Z d d l m Z d d l m Z d d l m Z d � Z d � Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys�
---
author: James Hogarth (@hogarthj)
module: jenkins_script
short_description: Executes a groovy script in the jenkins instance
version_added: '2.3'
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.
options:
script:
description:
- The groovy script to be executed.
This gets passed as a string Template if args is defined.
required: true
url:
description:
- The jenkins server to execute the script against. The default is a local
jenkins instance that is not being proxied through a webserver.
default: http://localhost:8080
validate_certs:
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
default: 'yes'
user:
description:
- The username to connect to the jenkins server with.
password:
description:
- The password to connect to the jenkins server with.
timeout:
description:
- The request timeout in seconds
default: 10
version_added: "2.4"
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).
notes:
- 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.
s�
- 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
sj
output:
description: Result of script
returned: success
type: str
sample: 'Result: true'
N( t
AnsibleModule( t http_cookiejar( t urlencode( t fetch_url( t to_nativec C` s� t | | j d d d d �\ } } | d d k ri | j d d t | d � d | d d
d � n t | j � � } t j | � j d t � S(
Nt urls /api/jsont methodt GETR i� t msgs HTTP error t t outputt t useCrumbs(
R t paramst fail_jsont strR t readt jsont loadst gett False( t modulet respt infot content( ( sU /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/jenkins_script.pyt is_csrf_protection_enabledr s 3c C` s� t | | j d d d d d | �\ } } | d d k ro | j d d t | d � d
| d d d � n t | j � � } t j | � S(
NR
s /crumbIssuer/api/jsonR R t cookiesR i� R s HTTP error R R R ( R R R R R R R R ( R R"