跳到主要内容

在环境间复制工作#

将工作从一个n8n实例发送到另一个实例的步骤,根据您使用单个Git分支还是多个分支而有所不同。

单分支#

如果使用单个Git分支,复制工作的步骤为:

  1. 将工作从一个实例推送到Git分支
  2. 登录另一个实例从Git拉取工作。您可以自动执行拉取操作

多分支#

如果拥有多个Git分支,需要在Git提供商处合并分支以实现环境间的工作复制。无法直接在n8n中的环境间复制工作。

常见模式为:

  1. 在开发实例中完成工作
  2. 将工作推送到Git中的开发分支
  3. 将开发分支合并到生产分支。请参考Git提供商的文档进行操作:
  4. 在生产n8n实例中拉取变更。您可以自动执行拉取操作

自动向n8n发送变更#

您可以使用/source-control/pull API端点自动化部分工作复制流程。在合并变更后调用该API:

curl --request POST \
--location '<YOUR-INSTANCE-URL>/api/v1/source-control/pull' \
--header 'Content-Type: application/json' \
--header 'X-N8N-API-KEY: <YOUR-API-KEY>' \
--data '{"force": true}'

这意味着您可以使用 GitHub Action 或 GitLab CI/CD 在合并时自动将更改拉取到生产实例。

GitHub Action 示例:

name: CI
on:
# Trigger the workflow on push or pull request events for the "production" branch
push:
branches: [ "production" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
run-pull:
runs-on: ubuntu-latest
steps:
- name: PULL
# Use GitHub secrets to protect sensitive information
run: >
curl --location '${{ secrets.INSTANCE_URL }}/version-control/pull' --header
'Content-Type: application/json' --header 'X-N8N-API-KEY: ${{ secrets.INSTANCE_API_KEY }}'