Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

GitHub Actions 变量

使用 REST API 与 GitHub Actions 中的变量进行交互。

关于 GitHub Actions 中的变量

可以使用 REST API 创建、更新、删除和检索可在 GitHub Actions 中的工作流中使用的变量的信息。 变量允许在存储库、存储库环境或组织中存储非敏感信息,例如用户名。 有关更多信息,请参阅 GitHub Actions 文档中的《AUTOTITLE》

List organization variables

Works with GitHub Apps

Lists all organization variables. You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:read organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "List organization variables"

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

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

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

The organization name. The name is not case sensitive.

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

The number of results per page (max 30).

默认: 10

page integer

Page number of the results to fetch.

默认: 1

HTTP response status codes for "List organization variables"

Status codeDescription
200

OK

Code samples for "List organization variables"

get/orgs/{org}/actions/variables
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables

Response

Status: 200
{ "total_count": 3, "variables": [ { "name": "USERNAME", "value": "octocat", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "private" }, { "name": "ACTIONS_RUNNER_DEBUG", "value": true, "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "all" }, { "name": "ADMIN_EMAIL", "value": "octocat@github.com", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "selected", "selected_repositories_url": "https://api.github.com/orgs/octo-org/actions/variables/ADMIN_EMAIL/repositories" } ] }

Create an organization variable

Works with GitHub Apps

Creates an organization variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Create an organization variable"

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

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

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

The organization name. The name is not case sensitive.

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

The name of the variable.

value string 必须

The value of the variable.

visibility string 必须

The type of repositories in the organization that can access the variable. selected means only the repositories specified by selected_repository_ids can access the variable.

可以是以下选项之一: all, private, selected

selected_repository_ids array of integers

An array of repository ids that can access the organization variable. You can only provide a list of repository ids when the visibility is set to selected.

HTTP response status codes for "Create an organization variable"

Status codeDescription
201

Response when creating a variable

Code samples for "Create an organization variable"

post/orgs/{org}/actions/variables
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables \ -d '{"name":"USERNAME","value":"octocat","visibility":"selected","selected_repository_ids":[1296269,1296280]}'

Response when creating a variable

Get an organization variable

Works with GitHub Apps

Gets a specific variable in an organization.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:read organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Get an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

HTTP response status codes for "Get an organization variable"

Status codeDescription
200

OK

Code samples for "Get an organization variable"

get/orgs/{org}/actions/variables/{name}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME

Response

Status: 200
{ "name": "USERNAME", "value": "octocat", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "selected", "selected_repositories_url": "https://api.github.com/orgs/octo-org/actions/variables/USERNAME/repositories" }

Update an organization variable

Works with GitHub Apps

Updates an organization variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Update an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

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

The name of the variable.

value string

The value of the variable.

visibility string

The type of repositories in the organization that can access the variable. selected means only the repositories specified by selected_repository_ids can access the variable.

可以是以下选项之一: all, private, selected

selected_repository_ids array of integers

An array of repository ids that can access the organization variable. You can only provide a list of repository ids when the visibility is set to selected.

HTTP response status codes for "Update an organization variable"

Status codeDescription
204

No Content

Code samples for "Update an organization variable"

patch/orgs/{org}/actions/variables/{name}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME \ -d '{"name":"USERNAME","value":"octocat","visibility":"selected","selected_repository_ids":[1296269,1296280]}'

Response

Status: 204

Delete an organization variable

Works with GitHub Apps

Deletes an organization variable using the variable name.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Delete an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

HTTP response status codes for "Delete an organization variable"

Status codeDescription
204

No Content

Code samples for "Delete an organization variable"

delete/orgs/{org}/actions/variables/{name}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME

Response

Status: 204

List selected repositories for an organization variable

Works with GitHub Apps

Lists all repositories that can access an organization variable that is available to selected repositories.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:read organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "List selected repositories for an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

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

Page number of the results to fetch.

默认: 1

per_page integer

The number of results per page (max 100).

默认: 30

HTTP response status codes for "List selected repositories for an organization variable"

Status codeDescription
200

OK

409

Response when the visibility of the variable is not set to selected

Code samples for "List selected repositories for an organization variable"

get/orgs/{org}/actions/variables/{name}/repositories
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME/repositories

Response

Status: 200
{ "total_count": 1, "repositories": [ { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "git@github.com:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks" } ] }

Set selected repositories for an organization variable

Works with GitHub Apps

Replaces all repositories for an organization variable that is available to selected repositories. Organization variables that are available to selected repositories have their visibility field set to selected.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Set selected repositories for an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

正文参数
名称, 类型, 说明
selected_repository_ids array of integers 必须

The IDs of the repositories that can access the organization variable.

HTTP response status codes for "Set selected repositories for an organization variable"

Status codeDescription
204

No Content

409

Response when the visibility of the variable is not set to selected

Code samples for "Set selected repositories for an organization variable"

put/orgs/{org}/actions/variables/{name}/repositories
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME/repositories \ -d '{"selected_repository_ids":[64780797]}'

Response

Status: 204

Add selected repository to an organization variable

Works with GitHub Apps

Adds a repository to an organization variable that is available to selected repositories. Organization variables that are available to selected repositories have their visibility field set to selected.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Add selected repository to an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

repository_id integer 必须

HTTP response status codes for "Add selected repository to an organization variable"

Status codeDescription
204

No Content

409

Response when the visibility of the variable is not set to selected

Code samples for "Add selected repository to an organization variable"

put/orgs/{org}/actions/variables/{name}/repositories/{repository_id}
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME/repositories/REPOSITORY_ID

Response

Status: 204

Remove selected repository from an organization variable

Works with GitHub Apps

Removes a repository from an organization variable that is available to selected repositories. Organization variables that are available to selected repositories have their visibility field set to selected.

You must authenticate using an access token with the admin:org scope to use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the organization_actions_variables:write organization permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Remove selected repository from an organization variable"

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

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

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

The organization name. The name is not case sensitive.

name string 必须

The name of the variable.

repository_id integer 必须

HTTP response status codes for "Remove selected repository from an organization variable"

Status codeDescription
204

No Content

409

Response when the visibility of the variable is not set to selected

Code samples for "Remove selected repository from an organization variable"

delete/orgs/{org}/actions/variables/{name}/repositories/{repository_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/actions/variables/NAME/repositories/REPOSITORY_ID

Response

Status: 204

List repository organization variables

Works with GitHub Apps

Lists all organiation variables shared with a repository.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:read repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "List repository organization variables"

标头
名称, 类型, 说明
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.

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

The number of results per page (max 30).

默认: 10

page integer

Page number of the results to fetch.

默认: 1

HTTP response status codes for "List repository organization variables"

Status codeDescription
200

OK

Code samples for "List repository organization variables"

get/repos/{owner}/{repo}/actions/organization-variables
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/organization-variables

Response

Status: 200
{ "total_count": 2, "variables": [ { "name": "USERNAME", "value": "octocat", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z" }, { "name": "EMAIL", "value": "octocat@github.com", "created_at": "2020-01-10T10:59:22Z", "updated_at": "2020-01-11T11:59:22Z" } ] }

List repository variables

Works with GitHub Apps

Lists all repository variables. You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:read repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "List repository variables"

标头
名称, 类型, 说明
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.

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

The number of results per page (max 30).

默认: 10

page integer

Page number of the results to fetch.

默认: 1

HTTP response status codes for "List repository variables"

Status codeDescription
200

OK

Code samples for "List repository variables"

get/repos/{owner}/{repo}/actions/variables
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/variables

Response

Status: 200
{ "total_count": 2, "variables": [ { "name": "USERNAME", "value": "octocat", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z" }, { "name": "EMAIL", "value": "octocat@github.com", "created_at": "2020-01-10T10:59:22Z", "updated_at": "2020-01-11T11:59:22Z" } ] }

Create a repository variable

Works with GitHub Apps

Creates a repository variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Create a repository variable"

标头
名称, 类型, 说明
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.

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

The name of the variable.

value string 必须

The value of the variable.

HTTP response status codes for "Create a repository variable"

Status codeDescription
201

Created

Code samples for "Create a repository variable"

post/repos/{owner}/{repo}/actions/variables
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/variables \ -d '{"name":"USERNAME","value":"octocat"}'

Response

Get a repository variable

Works with GitHub Apps

Gets a specific variable in a repository.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:read repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Get a repository variable"

标头
名称, 类型, 说明
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.

name string 必须

The name of the variable.

HTTP response status codes for "Get a repository variable"

Status codeDescription
200

OK

Code samples for "Get a repository variable"

get/repos/{owner}/{repo}/actions/variables/{name}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/variables/NAME

Response

Status: 200
{ "name": "USERNAME", "value": "octocat", "created_at": "2021-08-10T14:59:22Z", "updated_at": "2022-01-10T14:59:22Z" }

Update a repository variable

Works with GitHub Apps

Updates a repository variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Update a repository variable"

标头
名称, 类型, 说明
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.

name string 必须

The name of the variable.

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

The name of the variable.

value string

The value of the variable.

HTTP response status codes for "Update a repository variable"

Status codeDescription
204

No Content

Code samples for "Update a repository variable"

patch/repos/{owner}/{repo}/actions/variables/{name}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/variables/NAME \ -d '{"name":"USERNAME","value":"octocat"}'

Response

Status: 204

Delete a repository variable

Works with GitHub Apps

Deletes a repository variable using the variable name.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the actions_variables:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Delete a repository variable"

标头
名称, 类型, 说明
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.

name string 必须

The name of the variable.

HTTP response status codes for "Delete a repository variable"

Status codeDescription
204

No Content

Code samples for "Delete a repository variable"

delete/repos/{owner}/{repo}/actions/variables/{name}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/actions/variables/NAME

Response

Status: 204

List environment variables

Works with GitHub Apps

Lists all environment variables.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the environments:read repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "List environment variables"

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

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

路径参数
名称, 类型, 说明
repository_id integer 必须

The unique identifier of the repository.

environment_name string 必须

The name of the environment.

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

The number of results per page (max 30).

默认: 10

page integer

Page number of the results to fetch.

默认: 1

HTTP response status codes for "List environment variables"

Status codeDescription
200

OK

Code samples for "List environment variables"

get/repositories/{repository_id}/environments/{environment_name}/variables
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repositories/REPOSITORY_ID/environments/ENVIRONMENT_NAME/variables

Response

Status: 200
{ "total_count": 2, "variables": [ { "name": "USERNAME", "value": "octocat", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z" }, { "name": "EMAIL", "value": "octocat@github.com", "created_at": "2020-01-10T10:59:22Z", "updated_at": "2020-01-11T11:59:22Z" } ] }

Create an environment variable

Works with GitHub Apps

Create an environment variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the environment:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Create an environment variable"

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

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

路径参数
名称, 类型, 说明
repository_id integer 必须

The unique identifier of the repository.

environment_name string 必须

The name of the environment.

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

The name of the variable.

value string 必须

The value of the variable.

HTTP response status codes for "Create an environment variable"

Status codeDescription
201

Created

Code samples for "Create an environment variable"

post/repositories/{repository_id}/environments/{environment_name}/variables
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repositories/REPOSITORY_ID/environments/ENVIRONMENT_NAME/variables \ -d '{"name":"USERNAME","value":"octocat"}'

Response

Get an environment variable

Works with GitHub Apps

Gets a specific variable in an environment.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the environments:read repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Get an environment variable"

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

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

路径参数
名称, 类型, 说明
repository_id integer 必须

The unique identifier of the repository.

environment_name string 必须

The name of the environment.

name string 必须

The name of the variable.

HTTP response status codes for "Get an environment variable"

Status codeDescription
200

OK

Code samples for "Get an environment variable"

get/repositories/{repository_id}/environments/{environment_name}/variables/{name}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repositories/REPOSITORY_ID/environments/ENVIRONMENT_NAME/variables/NAME

Response

Status: 200
{ "name": "USERNAME", "value": "octocat", "created_at": "2021-08-10T14:59:22Z", "updated_at": "2022-01-10T14:59:22Z" }

Update an environment variable

Works with GitHub Apps

Updates an environment variable that you can reference in a GitHub Actions workflow.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the environment:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Update an environment variable"

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

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

路径参数
名称, 类型, 说明
repository_id integer 必须

The unique identifier of the repository.

name string 必须

The name of the variable.

environment_name string 必须

The name of the environment.

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

The name of the variable.

value string

The value of the variable.

HTTP response status codes for "Update an environment variable"

Status codeDescription
204

No Content

Code samples for "Update an environment variable"

patch/repositories/{repository_id}/environments/{environment_name}/variables/{name}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repositories/REPOSITORY_ID/environments/ENVIRONMENT_NAME/variables/NAME \ -d '{"name":"USERNAME","value":"octocat"}'

Response

Status: 204

Delete an environment variable

Works with GitHub Apps

Deletes an environment variable using the variable name.

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the environment:write repository permission to use this endpoint. Authenticated users must have collaborator access to a repository to create, update, or read variables.

Parameters for "Delete an environment variable"

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

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

路径参数
名称, 类型, 说明
repository_id integer 必须

The unique identifier of the repository.

name string 必须

The name of the variable.

environment_name string 必须

The name of the environment.

HTTP response status codes for "Delete an environment variable"

Status codeDescription
204

No Content

Code samples for "Delete an environment variable"

delete/repositories/{repository_id}/environments/{environment_name}/variables/{name}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repositories/REPOSITORY_ID/environments/ENVIRONMENT_NAME/variables/NAME

Response

Status: 204