community.general.jenkins_job 模块 – 管理 Jenkins 任务

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您使用的是 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。

要在 Playbook 中使用它,请指定:community.general.jenkins_job

概要

  • 通过使用 Jenkins REST API 管理 Jenkins 任务。

要求

执行此模块的主机上需要以下要求。

  • python-jenkins >= 0.4.12

参数

参数

注释

config

字符串

XML 格式的配置。

如果任务尚不存在,则为必填项。

enabled 互斥。

如果 state=present 则考虑。

enabled

布尔值

是否应启用或禁用任务。

config 互斥。

如果 state=present 则考虑。

选项

  • false

  • true

name

字符串 / 必填

Jenkins 任务的名称。

password

字符串

用于向 Jenkins 服务器进行身份验证的密码。

state

字符串

指定是否必须创建或删除任务的属性。

选项

  • "present" ← (默认)

  • "absent"

token

字符串

用于替代密码进行身份验证的 API 令牌。

url

字符串

Jenkins 服务器可访问的 URL。

默认值: "https://127.0.0.1:8080"

user

字符串

用于向 Jenkins 服务器进行身份验证的用户。

validate_certs

布尔值

在 community.general 2.3.0 中添加

如果设置为 false,则不会验证 SSL 证书。只有在使用自签名证书的个人控制站点时,才应将其设置为 false,因为它避免了验证源站点。

python-jenkins 库仅通过使用环境变量 PYTHONHTTPSVERIFY 来处理此问题。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:完全

可以在 check_mode 中运行并返回更改状态预测,而无需修改目标。

diff_mode

支持:完全

在 diff 模式下,将返回有关已更改的内容(或可能需要在 check_mode 中更改的内容)的详细信息。

示例

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

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

- name: Delete a jenkins job using basic authentication
  community.general.jenkins_job:
    name: test
    password: admin
    state: absent
    url: https://127.0.0.1:8080
    user: admin

- name: Delete a jenkins job using the token
  community.general.jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    state: absent
    url: https://127.0.0.1:8080
    user: admin

- name: Disable a jenkins job using basic authentication
  community.general.jenkins_job:
    name: test
    password: admin
    enabled: false
    url: https://127.0.0.1:8080
    user: admin

- name: Disable a jenkins job using the token
  community.general.jenkins_job:
    name: test
    token: asdfasfasfasdfasdfadfasfasdfasdfc
    enabled: false
    url: https://127.0.0.1:8080
    user: admin

返回值

常见返回值记录在此处,以下是此模块特有的字段

描述

enabled

布尔值

Jenkins 任务是否已启用。

返回: 成功

示例: true

name

字符串

Jenkins 任务的名称。

返回: 成功

示例: "test-job"

state

字符串

Jenkins 任务的状态。

返回: 成功

示例: "present"

url

字符串

连接到 Jenkins 服务器的 URL。

返回: 成功

示例: "https://jenkins.mydomain.com"

user

字符串

用于身份验证的用户。

返回: 成功

示例: "admin"

作者

  • Sergio Millan Rodriguez (@sermilrod)