Skip to main content

此版本的 GitHub Enterprise Server 已于以下日期停止服务 2024-03-26. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

站点管理员将企业服务器实例升级为 Enterprise Server 3.9 或更高版本后,REST API 将进行版本控制。 若要了解如何查找实例的版本,请参阅“关于 GitHub Docs 的版本”。 有关详细信息,请参阅“关于 API 版本控制”。

适用于部署分支策略的 REST API 终结点

使用 REST API 管理自定义部署分支策略。

关于部署分支策略

可以使用 REST API 指定分支必须匹配才能部署到环境的自定义名称模式。 环境的 deployment_branch_policy.custom_branch_policies 属性必须设置为 true 才能使用这些终结点。 若要更新环境的 deployment_branch_policy,请参阅“适用于部署环境的 REST API 终结点”。

有关将环境部署限制为某些分支的详细信息,请参阅“使用环境进行部署”。

List deployment branch policies

Lists the deployment branch policies for an environment.

Anyone with read access to the repository can use this endpoint.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.

“List deployment branch policies”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

environment_name string 必须

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

默认: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

默认: 1

“List deployment branch policies”的 HTTP 响应状态代码

状态代码说明
200

OK

“List deployment branch policies”的示例代码

请求示例

get/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies

Response

Status: 200
{ "total_count": 2, "branch_policies": [ { "id": 361471, "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzE=", "name": "release/*" }, { "id": 361472, "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzI=", "name": "main" } ] }

Create a deployment branch policy

Creates a deployment branch policy for an environment.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Create a deployment branch policy”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

environment_name string 必须

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

正文参数
名称, 类型, 说明
name string 必须

The name pattern that branches or tags must match in order to deploy to the environment.

Wildcard characters will not match /. For example, to match branches that begin with release/ and contain an additional single slash, use release/*/*. For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.

“Create a deployment branch policy”的 HTTP 响应状态代码

状态代码说明
200

OK

303

Response if the same branch name pattern already exists

404

Not Found or deployment_branch_policy.custom_branch_policies property for the environment is set to false

“Create a deployment branch policy”的示例代码

请求示例

post/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \ -d '{"name":"release/*"}'

Response

Status: 200
{ "id": 364662, "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=", "name": "release/*" }

Get a deployment branch policy

Gets a deployment branch policy for an environment.

Anyone with read access to the repository can use this endpoint.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.

“Get a deployment branch policy”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

environment_name string 必须

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

branch_policy_id integer 必须

The unique identifier of the branch policy.

“Get a deployment branch policy”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get a deployment branch policy”的示例代码

请求示例

get/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID

Response

Status: 200
{ "id": 364662, "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=", "name": "release/*" }

Update a deployment branch policy

Updates a deployment branch policy for an environment.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Update a deployment branch policy”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

environment_name string 必须

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

branch_policy_id integer 必须

The unique identifier of the branch policy.

正文参数
名称, 类型, 说明
name string 必须

The name pattern that branches must match in order to deploy to the environment.

Wildcard characters will not match /. For example, to match branches that begin with release/ and contain an additional single slash, use release/*/*. For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.

“Update a deployment branch policy”的 HTTP 响应状态代码

状态代码说明
200

OK

“Update a deployment branch policy”的示例代码

请求示例

put/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID \ -d '{"name":"release/*"}'

Response

Status: 200
{ "id": 364662, "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=", "name": "release/*" }

Delete a deployment branch policy

Deletes a deployment branch policy for an environment.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Delete a deployment branch policy”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

environment_name string 必须

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

branch_policy_id integer 必须

The unique identifier of the branch policy.

“Delete a deployment branch policy”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Delete a deployment branch policy”的示例代码

请求示例

delete/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID

Response

Status: 204