Skip to content

Copy work between environments#

ขั้นตอนการส่งงานจาก n8n instance หนึ่งไปอีกอันจะต่างกัน ขึ้นอยู่กับว่าคุณใช้ Git branch เดียวหรือหลาย branch

Single branch#

ถ้าคุณใช้ Git branch เดียว ขั้นตอน copy งานคือ:

  1. push งานจาก instance หนึ่งไปที่ Git branch
  2. login เข้าอีก instance เพื่อ pull งานจาก Git คุณสามารถ automate pulls ได้

Multiple branches#

ถ้าคุณมี Git branch มากกว่าหนึ่ง คุณต้อง merge branch ใน Git provider เพื่อ copy งานระหว่าง environments คุณไม่สามารถ copy งานตรงๆ ระหว่าง environments ใน n8n ได้

pattern ที่เจอบ่อยคือ:

  1. ทำงานใน development instance
  2. push งานไปที่ development branch ใน Git
  3. merge development branch เข้า production branch ดูวิธี merge ได้ที่:
  4. ใน production n8n instance ให้ pull การเปลี่ยนแปลง คุณสามารถ automate pulls ได้

Automatically send changes to n8n#

คุณสามารถ automate บางส่วนของการ copy งานได้ โดยใช้ endpoint /source-control/pull ของ API เรียก API หลัง merge เสร็จ:

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 เพื่อ pull งานเข้า production instance อัตโนมัติหลัง merge

ตัวอย่าง 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 }}'