jenkins_job - Manage jenkins jobs

New in version 2.2.

Synopsis

  • Manage Jenkins jobs by using Jenkins REST API.

Requirements (on host that executes module)

  • python-jenkins >= 0.4.12
  • lxml >= 3.3.3

Options

parameter required default choices comments
config
no
config in XML format.
Required if job does not yet exist.
Mututally exclusive with enabled.
Considered if state=present.
enabled
no
Whether the job should be enabled or disabled.
Mututally exclusive with config.
Considered if state=present.
name
yes
Name of the Jenkins job.
password
no
Password to authenticate with the Jenkins server.
state
no present
  • present
  • absent
Attribute that specifies if the job has to be created or deleted.
token
no
API token used to authenticate alternatively to password.
url
no http://localhost:8080
Url where the Jenkins server is accessible.
user
no
User to authenticate with the Jenkins server.

Examples

# Create a jenkins job using basic authentication
- jenkins_job:
    config: "{{ lookup('file', 'templates/test.xml') }}"
    name: test
    password: admin
    url: http://localhost:8080
    user: admin

# Create a jenkins job using the token
- jenkins_job:
    config: "{{ lookup('template', 'templates/test.xml.j2') }}"
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    url: http://localhost:8080
    user: admin

# Delete a jenkins job using basic authentication
- jenkins_job:
    name: test
    password: admin
    state: absent
    url: http://localhost:8080
    user: admin

# Delete a jenkins job using the token
- jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    state: absent
    url: http://localhost:8080
    user: admin

# Disable a jenkins job using basic authentication
- jenkins_job:
    name: test
    password: admin
    enabled: False
    url: http://localhost:8080
    user: admin

# Disable a jenkins job using the token
- jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    enabled: False
    url: http://localhost:8080
    user: admin

Return Values

Common return values are documented here Return Values, the following are the fields unique to this module:

name description returned type sample
enabled
Whether the jenkins job is enabled or not.
success bool True
name
Name of the jenkins job.
success string test-job
state
State of the jenkins job.
success string present
url
Url to connect to the Jenkins server.
success string https://jenkins.mydomain.com
user
User used for authentication.
success string admin

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_job_module.html