gh secret set
gh secret set <secret-name> [flags]
为以下级别之一的秘密设置值:
- 仓库(默认):可用于 GitHub Actions 运行或仓库中的 Dependabot
- 环境:可用于仓库中部署环境的 GitHub Actions 运行
- 组织:可用于组织内的 GitHub Actions 运行、Dependabot 或 Codespaces
- 用户:可用于您的用户的 Codespaces
组织和用户秘密可以选择性地限制为仅对特定仓库可用。
秘密值在发送到 GitHub 之前会在本地加密。
选项
-a
,--app <string>
- 为秘密设置应用程序:{actions|codespaces|dependabot}
-b
,--body <string>
- 秘密的值(如果未指定,则从标准输入读取)
-e
,--env <environment>
- 设置部署环境秘密
-f
,--env-file <file>
- 从 dotenv 格式的文件中加载秘密名称和值
-
--no-store
- 打印加密的 base64 编码值,而不是将其存储在 GitHub 上
-o
,--org <organization>
- 设置组织秘密
-r
,--repos <repositories>
- 可以访问组织或用户秘密的仓库列表
-u
,--user
- 为您的用户设置秘密
-v
,--visibility <string> (default "private")
- 为组织秘密设置可见性:{all|private|selected}
从父命令继承的选项
-R
,--repo <[HOST/]OWNER/REPO>
- 使用 [HOST/]OWNER/REPO 格式选择另一个仓库
示例
# Paste secret value for the current repository in an interactive prompt
$ gh secret set MYSECRET
# Read secret value from an environment variable
$ gh secret set MYSECRET --body "$ENV_VALUE"
# Read secret value from a file
$ gh secret set MYSECRET < myfile.txt
# Set secret for a deployment environment in the current repository
$ gh secret set MYSECRET --env myenvironment
# Set organization-level secret visible to both public and private repositories
$ gh secret set MYSECRET --org myOrg --visibility all
# Set organization-level secret visible to specific repositories
$ gh secret set MYSECRET --org myOrg --repos repo1,repo2,repo3
# Set user-level secret for Codespaces
$ gh secret set MYSECRET --user
# Set repository-level secret for Dependabot
$ gh secret set MYSECRET --app dependabot
# Set multiple secrets imported from the ".env" file
$ gh secret set -f .env
# Set multiple secrets from stdin
$ gh secret set -f - < myfile.txt