Skip to content

Set up source control for environments#

เชื่อม Git repository กับ n8n instance แล้วตั้งค่า source control

n8n ใช้ source control เพื่อรองรับ environments ดูรายละเอียดที่ Environments in n8n

Prerequisites#

ถ้าจะใช้ source control กับ n8n คุณต้องมี Git repository ที่รองรับ SSH access

เอกสารนี้สมมติว่าคุณคุ้นเคยกับ Git และ Git provider ของคุณ

Step 1: Set up your repository and branches#

สำหรับ setup ใหม่:

  1. สร้าง repository ใหม่สำหรับใช้กับ n8n
  2. สร้าง branch ที่ต้องใช้ เช่น ถ้าจะมี environment แยก test กับ production ให้สร้าง branch สำหรับแต่ละอัน

ถ้าอยากตัดสินใจว่า use case ของคุณควรมี branch อะไรบ้าง ดูที่ Branch patterns

Step 2: Configure Git in n8n#

  1. ไปที่ Settings > Environments
  2. ในช่อง Git repository URL ให้ป้อน SSH URL สำหรับ repository ของคุณ
  3. n8n รองรับอัลกอริทึม public key แบบ ED25519 และ RSA โดย ED25519 เป็นค่าเริ่มต้น เลือก RSA ภายใต้ SSH Key หาก git host ของคุณต้องการ RSA
  4. คัดลอก SSH key

Step 3: Set up a deploy key#

ตั้งค่า SSH access โดยสร้าง deploy key ให้ repository โดยใช้ SSH key จาก n8n ต้องให้สิทธิ์ write ด้วย

แต่ละ Git provider จะมีขั้นตอนต่างกัน ดูวิธีได้ที่:

Step 4: Connect n8n and configure your instance#

  1. ที่ Settings > Environments ใน n8n ให้เลือก Connect เพื่อเชื่อมกับ Git repository
  2. ที่ Instance settings เลือก branch ที่จะใช้กับ n8n instance นี้
  3. Optional: เลือก Protected instance เพื่อป้องกันไม่ให้ user แก้ workflow ใน instance นี้ เหมาะกับ production instance
  4. Optional: เลือกสี custom ให้ instance สีนี้จะโชว์ในเมนูข้างปุ่ม push/pull source control ช่วยให้ user รู้ว่าอยู่ instance ไหน
  5. เลือก Save settings