Skip to content

设置环境源代码控制(Set up source control for environments)#

将 Git 仓库链接到 n8n 实例并配置源代码控制。

🌐 Link a Git repository to an n8n instance and configure your source control.

n8n 使用源代码控制来提供环境。有关更多信息,请参阅 n8n 中的环境

🌐 n8n uses source control to provide environments. Refer to Environments in n8n for more information.

先决条件(Prerequisites)#

要将 n8n 与源代码控制一起使用,你需要一个 Git 仓库,并满足以下条件之一:

🌐 To use source control with n8n, you need a Git repository with either:

  • SSH 访问(使用部署密钥),或
  • HTTPS 访问(使用个人访问令牌)

本文档假设你熟悉 Git 及其 Git 提供商。

🌐 This document assumes you are familiar with Git and your Git provider.

步骤 1:设置你的仓库和分支(Step 1: Set up your repository and branches)#

全新设置:

🌐 For a new setup:

  1. 创建一个用于 n8n 的新存储库。
  2. 创建你需要的分支。例如,如果你打算为测试和生产环境设置不同的环境,请为每个环境创建一个分支。

要帮助决定你的使用场景需要哪些分支,请参考 分支模式

🌐 To help decide what branches you need for your use case, refer to Branch patterns.

步骤 2:在 n8n 中配置 Git(Step 2: Configure Git in n8n)#

  1. Go to Settings > Environments.
  2. Choose your connection method:
    • SSH: In Git repository URL, enter the SSH URL for your repository (for example, git@github.com:username/repo.git).
    • HTTPS: In Git repository URL enter the HTTPS URL for your repository (for example, https://github.com/username/repo.git).
  3. Configure authentication based on your connection method:
    • For SSH: n8n supports ED25519 and RSA public key algorithms. ED25519 is the default. Select RSA under SSH Key if your git host requires RSA. Copy the SSH key.
    • For HTTPS: Enter your credentials:
      • Username: Your Git provider username.
      • Token: Your Personal Access Token (PAT) from your Git provider.

步骤3:设置身份验证(Step 3: Set up authentication)#

根据你选择的连接方式配置身份验证。

🌐 Configure authentication based on your chosen connection method.

SSH 身份验证(使用 deploy 命令)密钥)(SSH authentication (using deploy keys))#

通过使用 n8n 的 SSH 密钥为仓库创建部署密钥来设置 SSH 访问。该密钥必须具有写入权限。

🌐 Set up SSH access by creating a deploy key for the repository using the SSH key from n8n. The key must have write access.

具体步骤取决于你的 Git 提供商。常见提供商的帮助链接:

🌐 The steps depend on your Git provider. Help links for common providers:

HTTPS 身份验证(使用个人访问令牌)(HTTPS authentication (using Personal Access Tokens))#

创建具有存储库访问权限的个人访问令牌 (PAT)。

🌐 Create a Personal Access Token (PAT) with repository access permissions.

使用常用提供商创建 PAT 的帮助链接:

🌐 Help links for creating PATs with common providers:

你的令牌所需的权限:

🌐 Required permissions for your token:

  • 存储库读/写权限
  • 内容读/写(适用于 GitHub)
  • 源代码拉取/推送(适用于 GitLab)

步骤 4:连接 n8n 并配置你的实例(Step 4: Connect n8n and configure your instance)#

  1. 在 n8n 的 设置 > 环境 中,选择 连接。n8n 将连接到你的 Git 仓库。
  2. 实例设置中,选择你想要用于当前 n8n 实例的分支。
  3. 可选:选择受保护实例以防止用户编辑此实例中的工作流。这对于保护生产实例非常有用。
  4. 可选:为实例选择自定义颜色。这将在菜单中显示,位于源代码管理的推送和拉取按钮旁边。它有助于用户了解自己当前在哪个实例中。
  5. 选择 保存设置