Deployment Environments 用 REST API エンドポイント
REST API を使って、デプロイ環境を作成、構成、削除します。
デプロイ環境について
環境の詳細については、「デプロイに環境の使用」を参照してください。 環境シークレットを管理する方法については、「GitHub Actions シークレットの REST API エンドポイント」を参照してください。
環境、環境シークレット、およびデプロイ保護ルールは、現在のすべての GitHub プランのパブリック リポジトリで使用できます。 ブロンズ、シルバー、ゴールドなどの従来のプランでは使用できません。 プライベートまたは内部リポジトリ内の環境、環境のシークレット、デプロイ ブランチにアクセスするには、GitHub Pro、GitHub Team または GitHub Enterprise を使う必要があります。
List environments
Lists the environments for a repository.
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 environments" のきめ細かいアクセス トークン
このエンドポイントは、次の粒度の細かいトークンの種類で動作します:
粒度の細かいトークンには次のアクセス許可セットが設定されている必要があります:
- "Actions" repository permissions (read)
このエンドポイントは、パブリック リソースのみが要求される場合は、認証または前述メンションアクセス許可なしで使用できます。
"List environments" のパラメーター
名前, Type, 説明 |
---|
accept string Setting to |
名前, Type, 説明 |
---|
owner string 必須The account owner of the repository. The name is not case sensitive. |
repo string 必須The name of the repository without the |
名前, Type, 説明 |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Default: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Default: |
"List environments" の HTTP 応答状態コード
状態コード | 説明 |
---|---|
200 | OK |
"List environments" のコード サンプル
要求の例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments
Response
Status: 200
{
"total_count": 1,
"environments": [
{
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://HOSTNAME/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"prevent_self_review": false,
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/users/octocat/received_events",
"type": "User",
"site_admin": false
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://HOSTNAME/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://HOSTNAME/teams/1/members{/member}",
"repositories_url": "https://HOSTNAME/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": "trues"
}
}
]
}
Get an environment
Note
To get information about name patterns that branches must match in order to deploy to this environment, see "Get a deployment branch policy."
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 an environment" のきめ細かいアクセス トークン
このエンドポイントは、次の粒度の細かいトークンの種類で動作します:
粒度の細かいトークンには次のアクセス許可セットが設定されている必要があります:
- "Actions" repository permissions (read)
このエンドポイントは、パブリック リソースのみが要求される場合は、認証または前述メンションアクセス許可なしで使用できます。
"Get an environment" のパラメーター
名前, Type, 説明 |
---|
accept string Setting to |
名前, Type, 説明 |
---|
owner string 必須The account owner of the repository. The name is not case sensitive. |
repo string 必須The name of the repository without the |
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 |
"Get an environment" の HTTP 応答状態コード
状態コード | 説明 |
---|---|
200 | OK |
"Get an environment" のコード サンプル
要求の例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME
Response
Status: 200
{
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://HOSTNAME/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"prevent_self_review": false,
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/users/octocat/received_events",
"type": "User",
"site_admin": false
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://HOSTNAME/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://HOSTNAME/teams/1/members{/member}",
"repositories_url": "https://HOSTNAME/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}
Create or update an environment
Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments."
Note
To create or update name patterns that branches must match in order to deploy to this environment, see "Deployment branch policies."
Note
To create or update secrets for an environment, see "GitHub Actions secrets."
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint.
"Create or update an environment" のきめ細かいアクセス トークン
このエンドポイントは、次の粒度の細かいトークンの種類で動作します:
粒度の細かいトークンには次のアクセス許可セットが設定されている必要があります:
- "Administration" repository permissions (write)
"Create or update an environment" のパラメーター
名前, Type, 説明 |
---|
accept string Setting to |
名前, Type, 説明 |
---|
owner string 必須The account owner of the repository. The name is not case sensitive. |
repo string 必須The name of the repository without the |
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 |
名前, Type, 説明 | |||
---|---|---|---|
wait_timer integer The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days). | |||
prevent_self_review boolean Whether or not a user who created the job is prevented from approving their own job. | |||
reviewers array of objects or null The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed. | |||
Properties of |
名前, Type, 説明 |
---|
type string The type of reviewer. 次のいずれかにできます: |
id integer The id of the user or team who can review the deployment |
deployment_branch_policy
object or null The type of deployment branch policy for this environment. To allow all branches to deploy, set to null
.
Properties of deployment_branch_policy
名前, Type, 説明 |
---|
protected_branches boolean 必須Whether only branches with branch protection rules can deploy to this environment. If |
custom_branch_policies boolean 必須Whether only branches that match the specified name patterns can deploy to this environment. If |
"Create or update an environment" の HTTP 応答状態コード
状態コード | 説明 |
---|---|
200 | OK |
422 | Validation error when the environment name is invalid or when |
"Create or update an environment" のコード サンプル
要求の例
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME \
-d '{"wait_timer":30,"prevent_self_review":false,"reviewers":[{"type":"User","id":1},{"type":"Team","id":1}],"deployment_branch_policy":{"protected_branches":false,"custom_branch_policies":true}}'
Response
Status: 200
{
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://HOSTNAME/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"prevent_self_review": false,
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/users/octocat/received_events",
"type": "User",
"site_admin": false
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://HOSTNAME/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://HOSTNAME/teams/1/members{/member}",
"repositories_url": "https://HOSTNAME/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}
Delete an environment
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint.
"Delete an environment" のきめ細かいアクセス トークン
このエンドポイントは、次の粒度の細かいトークンの種類で動作します:
粒度の細かいトークンには次のアクセス許可セットが設定されている必要があります:
- "Administration" repository permissions (write)
"Delete an environment" のパラメーター
名前, Type, 説明 |
---|
accept string Setting to |
名前, Type, 説明 |
---|
owner string 必須The account owner of the repository. The name is not case sensitive. |
repo string 必須The name of the repository without the |
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 |
"Delete an environment" の HTTP 応答状態コード
状態コード | 説明 |
---|---|
204 | Default response |
"Delete an environment" のコード サンプル
要求の例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME
Default response
Status: 204