community.general.gitlab_hook 模块 – 管理 GitLab 项目钩子

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,详情请参阅要求

要在 playbook 中使用它,请指定:community.general.gitlab_hook

概要

  • 添加、更新和删除项目钩子

要求

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

参数

参数

注释

api_job_token

字符串

在 community.general 4.2.0 中添加

用于登录的 GitLab CI 作业令牌。

api_oauth_token

字符串

在 community.general 4.2.0 中添加

用于登录的 GitLab OAuth 令牌。

api_password

字符串

用于对 API 进行身份验证的密码。

api_token

字符串

具有 API 权限的 GitLab 访问令牌。

api_url

字符串

API 的可解析端点。

api_username

字符串

用于对 API 进行身份验证的用户名。

ca_path

字符串

在 community.general 8.1.0 中添加

用于验证 GitLab 服务器证书的 CA 证书包。

hook_url

字符串 / 必需

您希望 GitLab 发布到的 URL,这用作更新和删除的主键。

hook_validate_certs

别名: enable_ssl_verification

布尔值

GitLab 在触发钩子时是否进行 SSL 验证。

选项

  • false ← (默认)

  • true

issues_events

布尔值

在问题事件上触发钩子。

选项

  • false ← (默认)

  • true

job_events

布尔值

在作业事件上触发钩子。

选项

  • false ← (默认)

  • true

merge_requests_events

布尔值

在合并请求事件上触发钩子。

选项

  • false ← (默认)

  • true

note_events

布尔值

在注释事件或有人添加评论时触发钩子。

选项

  • false ← (默认)

  • true

pipeline_events

布尔值

在流水线事件上触发钩子。

选项

  • false ← (默认)

  • true

project

字符串 / 必需

项目 ID 或完整路径,格式为 group/name。

push_events

布尔值

在推送事件上触发钩子。

选项

  • false

  • true ← (默认)

push_events_branch_filter

字符串

在 community.general 0.2.0 中添加

触发推送事件钩子的分支名称或通配符

默认值: ""

releases_events

布尔值

在 community.general 8.4.0 中添加

在发布事件上触发钩子。

选项

  • false

  • true

state

字符串

present 时,钩子将更新以匹配输入,如果不存在则创建。

absent 时,如果存在则删除钩子。

选项

  • "present" ← (默认)

  • "absent"

tag_push_events

布尔值

在标签推送事件上触发钩子。

选项

  • false ← (默认)

  • true

token

字符串

用于在接收器验证钩子消息的密钥令牌。

如果存在,它将始终导致更改,因为它无法从 GitLab 检索。

将显示在 X-GitLab-Token HTTP 请求标头中。

validate_certs

布尔值

在提供 HTTPS 端点时是否验证 SSL 证书。

选项

  • false

  • true ← (默认)

wiki_page_events

布尔值

在 Wiki 事件上触发钩子。

选项

  • false ← (默认)

  • true

属性

属性

支持

描述

check_mode

支持: 完整

可以在 check_mode 中运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:

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

示例

- name: "Adding a project hook"
  community.general.gitlab_hook:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    project: "my_group/my_project"
    hook_url: "https://my-ci-server.example.com/gitlab-hook"
    state: present
    push_events: true
    tag_push_events: true
    token: "my-super-secret-token-that-my-ci-server-will-check"

- name: "Delete the previous hook"
  community.general.gitlab_hook:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    project: "my_group/my_project"
    hook_url: "https://my-ci-server.example.com/gitlab-hook"
    state: absent

- name: "Delete a hook by numeric project id"
  community.general.gitlab_hook:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    project: 10
    hook_url: "https://my-ci-server.example.com/gitlab-hook"
    state: absent

返回值

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

描述

错误

字符串

GitLab API 返回的错误消息

返回: 失败

示例: "400: path is already in use"

钩子

字典

API 对象

返回: 总是

msg

字符串

成功或失败消息

返回: 总是

示例: "成功"

result

字典

来自服务器的 JSON 解析响应

返回: 总是

作者

  • Marcus Watkins (@marwatk)

  • Guillaume Martinez (@Lunik)