跳至内容

在环境之间复制工作#

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

单分支#

如果您有一个单独的Git分支,复制工作的步骤如下:

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

多分支#

如果您有多个Git分支,需要在Git提供商处合并分支以在不同环境间复制工作内容。无法直接在n8n中跨环境复制工作。

一个常见的模式是:

  1. 在您的开发实例中执行工作。
  2. 将工作推送到Git的开发分支。
  3. Merge your development branch into your production branch. Refer to the documentation for your Git provider for guidance on doing this:
  4. 在你的生产环境n8n实例中,拉取变更。你可以自动化拉取

自动将变更发送到n8n#

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

1
2
3
4
5
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示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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 }}'
优云智算