Drone CI 中文文档

触发构建

使用指定分支的最新提交触发一个构建。请注意,生成的构建是以事件类型 custom 触发创建的。

  • 触发默认分支最新提交的构建:

    1
    
    POST /api/repos/{namespace}/{name}/builds
    
  • 触发指定分支最新提交的构建:

    1
    
    POST /api/repos/{namespace}/{name}/builds?branch={branch}
    
  • 使用指定的分支和提交 sha 触发一个构建:

    1
    
    POST /api/repos/{namespace}/{name}/builds?branch={branch}&commit={commit}
    
  • 触发一个带有自定义参数的构建。这些参数将作为环境变量提供给你的流水线步骤。

    1
    
    POST /api/repos/{namespace}/{name}/builds?branch={branch}&{key=value}
    

以下是响应体的示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
    "id": 100207,
    "repo_id": 296163,
    "number": 42,
    "status": "pending",
    "event": "custom",
    "action": "sync",
    "link": "https://github.com/octoat/hello-world/compare/e3320539a4c0...9fc1ad6ebf12",
    "message": "updated README",
    "before": "e3320539a4c03ccfda992641646deb67d8bf98f3",
    "after": "9fc1ad6ebf12462f3f9773003e26b4c6f54a772e",
    "ref": "refs/heads/master",
    "source_repo": "spaceghost/hello-world",
    "source": "develop",
    "target": "master",
    "author_login": "octocat",
    "author_name": "The Octocat",
    "author_email": "octocat@github.com",
    "author_avatar": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
    "sender": "bradrydzewski",
    "started": 0,
    "finished": 0,
    "created": 1564085874,
    "updated": 1564085874,
    "version": 1,
    "stages": [
        {
            "id": 199937,
            "repo_id": 296163,
            "build_id": 100207,
            "number": 1,
            "name": "default",
            "kind": "pipeline",
            "type": "docker",
            "status": "pending",
            "errignore": false,
            "exit_code": 0,
            "machine": "15e89c0f84f1",
            "os": "linux",
            "arch": "amd64",
            "started": 0,
            "stopped": 0,
            "created": 1564085874,
            "updated": 1564086343,
            "version": 1,
            "on_success": true,
            "on_failure": false
        }
    ]
}

流水线配置

当你使用 API 触发构建时,产生的构建是以事件类型 custom 创建的。如果你定义了基于事件类型的流水线条件或构建步骤条件,你可能需要进行相应的更新。

流水线条件的例子包括以下自定义事件类型:

1
2
3
4
5
trigger:
  event:
  - push
  - pull_request
  - custom