Drone CI 中文文档

Configuration(配置覆盖)

你可以使用 Configuration 扩展来覆盖获取配置文件的过程(例如:.drone.yml)。这可以用来为不存在配置的项目返回默认或全局配置,甚至可以即时生成配置。对于其他用例,你应该考虑使用 conversion 配置转换 扩展

扩展配置

你可以通过向 Drone Server 提供以下配置参数来注册一个 configuration 扩展:

  • DRONE_YAML_ENDPOINT
    提供用于向一个扩展发出 http 请求的端点。
  • DRONE_YAML_SECRET
    提供用于验证对扩展的 http 请求的令牌。这个令牌在服务器和扩展之间共享。

扩展工作原理

Drone Server 向 Configuration 扩展发起 HTTP POST 请求以获取配置文件。如果配置扩展返回 204 状态码,则系统将回退到存储库中的配置文件。

扩展请求响应

Configuration 扩展接收一个 HTTP 请求以返回配置文件。请求正文以 JSON 格式包含存储库和构建的详细信息。

以下是请求体的定义:

1
2
3
4
class Request {
  repo: Repo;
  build: Build
}

以下是 Repository(存储库)结构体的的定义:

 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
class Repository {
    id: int64;
    uid: string;
    user_id: int64;
    namespace: string;
    name: string;
    slug: string;
    scm: string;
    git_http_url: string;
    git_ssh_url: string;
    link: string;
    default_branch: string;
    private: boolean;
    visibility: string;
    active: boolean;
    config: string;
    trusted: boolean;
    protected: boolean;
    ignore_forks: boolean;
    ignore_pulls: boolean;
    cancel_pulls: boolean;
    timeout: int64;
    counter: int64;
    synced: int64;
    created: int64;
    updated: int64;
    version: int64;
}

以下是 Build(构建信息)结构体的定义:

 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
class Build {
    id: int64;
    repo_id: int64;
    number: int64;
    parent: int64;
    status: string;
    error: string
    event: string;
    action: string;
    link: string;
    timestamp: int64;
    title: string;
    message: string;
    before: string;
    after: string;
    ref: string;
    source_repo: string;
    source: string;
    target: string;
    author_login: string;
    author_name: string;
    author_email: string;
    author_avatar: string;
    sender: string;
    params: [string][string];
    cron: string;
    deploy_to: string;
    deploy_id: int64;
    started: int64;
    finished: int64;
    created: int64;
    updated: int64;
    version: int64;
}

扩展请求响应

Configuration 扩展应该以 HTTP 200 响应代码和原始的配置文件响应请求。如果配置扩展返回 204 状态码,则系统将回退到存储库中的配置文件。

以下是响应体的结构定义:

1
2
3
class Config {
    data: string;
}

扩展请求鉴权

HTTP 请求根据 HTTP 签名规范草案使用共享 Secret 进行签名。请求接收者应该使用签名来验证 WebHook 的真实性和完整性。

起始项目 (模板)

如果你有兴趣创建一个 Config 扩展,我们建议使用我们的起始项目模板作为基础来启动开发。