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 访问(使用部署密钥),或

¥SSH access (using deploy keys), or

  • HTTPS 访问(使用个人访问令牌)

¥HTTPS access (using Personal Access Tokens)

本文档假设你熟悉 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 的新存储库。

¥Create a new repository for use with n8n. 2. 创建所需的分支。例如,如果你计划为测试和生产环境设置不同的环境,请为每个环境设置一个分支。

¥Create the branches you need. For example, if you plan to have different environments for test and production, set up a branch for each.

为了帮助你确定用例所需的分支,请参考 分支模式

¥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:

¥GitHub | Managing deploy keys

¥GitLab | Deploy keys

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:

¥GitHub | Managing personal access tokens

¥GitLab | Personal access tokens

¥Bitbucket | App passwords

你的令牌所需的权限:

¥Required permissions for your token:

  • 存储库读/写权限

¥Repository read/write access

  • 内容读/写(适用于 GitHub)

¥Contents read/write (for GitHub)

  • 源代码拉取/推送(适用于 GitLab)

¥Source code pull/push (for GitLab)

步骤 4:连接 n8n 并配置你的实例#

¥Step 4: Connect n8n and configure your instance

  1. 在 n8n 的“设置”>“环境”中,选择“连接”。n8n 连接到你的 Git 存储库。

¥In Settings > Environments in n8n, select Connect. n8n connects to your Git repository. 2. 在“实例设置”下,选择要用于当前 n8n 实例的分支。

¥Under Instance settings, choose which branch you want to use for the current n8n instance. 3. 可选的:选择“受保护的实例”以防止用户编辑此实例中的工作流。这对于保护生产实例非常有用。

¥Optional: select Protected instance to prevent users editing workflows in this instance. This is useful for protecting production instances. 4. 可选的:为实例选择自定义颜色。这将出现在源代码控制推送和拉取按钮旁边的菜单中。它帮助用户了解他们当前所处的实例。

¥Optional: choose a custom color for the instance. This will appear in the menu next to the source control push and pull buttons. It helps users know which instance they're in. 5. 选择“保存设置”。

¥Select Save settings.