Skip to main content

environments

Creates, updates, deletes, gets or lists an environments resource.

Overview

Nameenvironments
TypeResource
Idgithub.repos.environments

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
idinteger (int64)The id of the environment.
namestringThe name of the environment. (example: staging)
node_idstring (example: MDExOkVudmlyb25tZW50NTY3ODA0Mjg=)
created_atstring (date-time)The time that the environment was created, in ISO 8601 format. (example: 2020-11-23T22:00:40Z)
deployment_branch_policyobjectThe type of deployment branch policy for this environment. To allow all branches to deploy, set to null.
html_urlstring (example: https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging)
protection_rulesarrayBuilt-in deployment protection rules for the environment.
updated_atstring (date-time)The time that the environment was last updated, in ISO 8601 format. (example: 2020-11-23T22:00:40Z)
urlstring (example: https://api.github.com/repos/github/hello-world/environments/staging)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_environmentselectowner, repo, environment_name> [!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_all_environmentsselectowner, repoper_page, pageLists 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.
create_or_update_environmentinsertowner, repo, environment_nameCreate 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.
delete_an_environmentdeleteowner, repo, environment_nameOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
environment_namestringThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.
pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API."
per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API."

SELECT examples

> [!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.

SELECT
id,
name,
node_id,
created_at,
deployment_branch_policy,
html_url,
protection_rules,
updated_at,
url
FROM github.repos.environments
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND environment_name = '{{ environment_name }}' -- required
;

INSERT examples

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.

INSERT INTO github.repos.environments (
wait_timer,
prevent_self_review,
reviewers,
deployment_branch_policy,
owner,
repo,
environment_name
)
SELECT
{{ wait_timer }},
{{ prevent_self_review }},
'{{ reviewers }}',
'{{ deployment_branch_policy }}',
'{{ owner }}',
'{{ repo }}',
'{{ environment_name }}'
RETURNING
id,
name,
node_id,
created_at,
deployment_branch_policy,
html_url,
protection_rules,
updated_at,
url
;

DELETE examples

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

DELETE FROM github.repos.environments
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND environment_name = '{{ environment_name }}' --required
;