Using secrets in GitHub Actions
在 GitHub Actions 中使用密鑰
Learn how to create secrets at the repository, environment, and organization levels for GitHub Actions workflows.
學習如何在倉庫、環境和組織級別為 GitHub Actions 工作流創建密鑰。
Creating secrets for a repository為倉庫創建密鑰
To create secrets or variables on GitHub for a personal account repository, you must be the repository owner. To create secrets or variables on GitHub for an organization repository, you must have admin access. Lastly, to create secrets or variables for a personal account repository or an organization repository through the REST API, you must have collaborator access.
要在 GitHub 上為個人賬戶倉庫創建密鑰或變量,您必須是該倉庫的所有者。要在 GitHub 上為組織倉庫創建密鑰或變量,您必須具有 admin 訪問權限。最后,要通過 REST API 為個人賬戶倉庫或組織倉庫創建密鑰或變量,您必須具有協作者訪問權限。
-
On GitHub, navigate to the main page of the repository.
在 GitHub 上,導航到存儲庫的主頁面。 -
Under your repository name, click Settings. If you cannot see the “Settings” tab, select the dropdown menu, then click Settings.
在您的存儲庫名稱下方,點擊 設置 。如果您看不到“設置”選項卡,請選擇下拉菜單,然后點擊 設置 。 -
Screenshot of a repository header showing the tabs. The “Settings” tab is highlighted by a dark orange outline.
In the “Security” section of the sidebar, select Secrets and variables, then click Actions.
在側邊欄的"安全"部分,選擇機密和變量 ,然后點擊操作 。 -
Click the Secrets tab.
點擊 Secrets 標簽。 -
Screenshot of the “Actions secrets and variables” page. The “Secrets” tab is outlined in dark orange.
Click New repository secret.
點擊 新建倉庫密鑰 。In the Name field, type a name for your secret.
在名稱字段中,輸入您的密鑰的名稱。In the Secret field, enter the value for your secret.
在密鑰字段中,輸入您的密鑰的值。 -
Click Add secret.
點擊 添加密鑰 。
If your repository has environment secrets or can access secrets from the parent organization, then those secrets are also listed on this page.
如果您的倉庫有環境密鑰或可以訪問父組織的密鑰,那么這些密鑰也會列在此頁面上。
Creating secrets for an environment
為環境創建密鑰
To create secrets or variables for an environment in a personal account repository, you must be the repository owner. To create secrets or variables for an environment in an organization repository, you must have admin access. For more information on environments, see Managing environments for deployment.
要在個人賬戶存儲庫中為環境創建密鑰或變量,您必須是存儲庫的所有者。要在組織存儲庫中為環境創建密鑰或變量,您必須具有 admin 訪問權限。有關環境的更多信息,請參閱 管理部署的環境 。
-
On GitHub, navigate to the main page of the repository.
在 GitHub 上,導航到存儲庫的主頁面。 -
Under your repository name, click Settings. If you cannot see the “Settings” tab, select the dropdown menu, then click Settings.
在您的存儲庫名稱下方,點擊 設置 。如果您看不到“設置”選項卡,請選擇下拉菜單,然后點擊 設置 。 -
Screenshot of a repository header showing the tabs. The “Settings” tab is highlighted by a dark orange outline.
In the left sidebar, click Environments.
在左側邊欄中,點擊 環境 。 -
Click on the environment that you want to add a secret to.
點擊您要添加密鑰的環境。 -
Under Environment secrets, click Add secret.
在 環境密鑰 下,點擊 添加密鑰 。 -
Type a name for your secret in the Name input box.
在名稱輸入框中輸入您的機密名稱。 -
Enter the value for your secret.
輸入您的密鑰值。 -
Click Add secret.
點擊 添加密鑰 。
剩余的查看官方文檔
https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets