{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
你可以阅读更多关于通过 API 触发流水线的信息。
列出项目触发令牌
获取项目的流水线触发令牌列表。
GET /projects/:id/triggers
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://jihulab.example.com/api/v4/projects/1/triggers"
[
{
"id": 10,
"description": "my trigger",
"created_at": "2016-01-07T09:53:58.235Z",
"last_used": null,
"token": "6d056f63e50fe6f8c5f8f4aa10edb7",
"updated_at": "2016-01-07T09:53:58.235Z",
"owner": null
}
]
如果触发令牌是由经过身份验证的用户创建的,则会完整显示。其他用户创建的触发令牌会缩短为四个字符。
获取触发令牌详情
获取项目的流水线触发令牌的详细信息。
GET /projects/:id/triggers/:trigger_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
trigger_id |
integer | 是 | 触发 ID |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://jihulab.example.com/api/v4/projects/1/triggers/5"
{
"id": 10,
"description": "my trigger",
"created_at": "2016-01-07T09:53:58.235Z",
"last_used": null,
"token": "6d056f63e50fe6f8c5f8f4aa10edb7",
"updated_at": "2016-01-07T09:53:58.235Z",
"owner": null
}
创建触发令牌
为项目创建一个流水线触发令牌。
POST /projects/:id/triggers
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
description |
string | 是 | 触发名称 |
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--form description="my description" "https://jihulab.example.com/api/v4/projects/1/triggers"
{
"id": 10,
"description": "my trigger",
"created_at": "2016-01-07T09:53:58.235Z",
"last_used": null,
"token": "6d056f63e50fe6f8c5f8f4aa10edb7",
"updated_at": "2016-01-07T09:53:58.235Z",
"owner": null
}
更新流水线触发令牌
更新项目的流水线触发令牌。
PUT /projects/:id/triggers/:trigger_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
trigger_id |
integer | 是 | 触发 ID |
description |
string | 否 | 触发名称 |
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \
--form description="my description" "https://jihulab.example.com/api/v4/projects/1/triggers/10"
{
"id": 10,
"description": "my trigger",
"created_at": "2016-01-07T09:53:58.235Z",
"last_used": null,
"token": "6d056f63e50fe6f8c5f8f4aa10edb7",
"updated_at": "2016-01-07T09:53:58.235Z",
"owner": null
}
移除流水线触发令牌
移除项目的流水线触发令牌。
DELETE /projects/:id/triggers/:trigger_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
trigger_id |
integer | 是 | 触发 ID |
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://jihulab.example.com/api/v4/projects/1/triggers/5"
使用令牌触发流水线
{{< history >}}
-
inputs
属性在极狐GitLab 17.10 引入,使用名为ci_inputs_for_pipelines
的功能标志。 默认禁用。 - 在极狐GitLab 17.11 上,在 JihuLab.com、极狐GitLab私有化部署上启用。
{{< /history >}}
通过使用流水线触发令牌或CI/CD 作业令牌进行身份验证来触发流水线。
使用 CI/CD 作业令牌时,触发的流水线是一个多项目流水线。 发起请求的作业会与上游流水线相关联,这可以在流水线图中看到。
如果在作业中使用触发令牌,该作业不会与上游流水线相关联。
POST /projects/:id/trigger/pipeline
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
ref |
string | 是 | 要运行流水线的分支或标签。 |
token |
string | 是 | 触发令牌或 CI/CD 作业令牌。 |
variables |
hash | 否 | 包含流水线变量的键值对字符串映射。例如:{ VAR1: "value1", VAR2: "value2" } 。 |
inputs |
hash | 否 | 创建流水线时使用的输入键值对映射。 |
带变量的请求示例:
curl --request POST \
--form "variables[VAR1]=value1" \
--form "variables[VAR2]=value2" \
"https://jihulab.example.com/api/v4/projects/123/trigger/pipeline?token=2cb1840fb9dfc9fb0b7b1609cd29cb&ref=main"
带输入的请求示例:
curl --request POST \
--header "Content-Type: application/json" \
--data '{"inputs": {"environment": "environment", "scan_security": false, "level": 3}}' \
"https://jihulab.example.com/api/v4/projects/123/trigger/pipeline?token=2cb1840fb9dfc9fb0b7b1609cd29cb&ref=main"
响应示例:
{
"id": 257,
"iid": 118,
"project_id": 123,
"sha": "91e2711a93e5d9e8dddfeb6d003b636b25bf6fc9",
"ref": "main",
"status": "created",
"source": "trigger",
"created_at": "2022-03-31T01:12:49.068Z",
"updated_at": "2022-03-31T01:12:49.068Z",
"web_url": "http://127.0.0.1:3000/test-group/test-project/-/pipelines/257",
"before_sha": "0000000000000000000000000000000000000000",
"tag": false,
"yaml_errors": null,
"user": {
"id": 1,
"username": "root",
"name": "管理员",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://127.0.0.1:3000/root"
},
"started_at": null,
"finished_at": null,
"committed_at": null,
"duration": null,
"queued_duration": null,
"coverage": null,
"detailed_status": {
"icon": "status_created",
"text": "created",
"label": "created",
"group": "created",
"tooltip": "created",
"has_details": true,
"details_path": "/test-group/test-project/-/pipelines/257",
"illustration": null,
"favicon": "/assets/ci_favicons/favicon_status_created-4b975aa976d24e5a3ea7cd9a5713e6ce2cd9afd08b910415e96675de35f64955.png"
}
}