8
n8n 中文网amn8n.com

n8n自动更新

中级

这是一个DevOps领域的自动化工作流,包含 12 个节点。主要使用 If, Code, HttpRequest, ScheduleTrigger 等节点。 使用版本检查和Portainer Webhook自动化n8n更新

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "5TGOTlmPdfRCmmfe",
  "meta": {
    "instanceId": "dcb1c5ac6ea74a8d48a18ebc0df6103a2b23cb36997704a343a62b1831c8eccd"
  },
  "name": "n8n 自动更新",
  "tags": [],
  "nodes": [
    {
      "id": "f1b6e1f4-1de3-4334-8a6a-72917d5612e3",
      "name": "Portainer Webhook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1184,
        80
      ],
      "parameters": {
        "url": "https://portainer.tld.com/api/stacks/webhooks/606e8503-8824-43b1-a67c-cf95abbee1a8",
        "method": "POST",
        "options": {
          "response": {
            "response": {}
          },
          "allowUnauthorizedCerts": false
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8cde31ed-6b9c-4451-8ce7-95b846d7e356",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        80
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 16,
              "triggerAtMinute": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8756bed1-42d0-4f5f-904c-2d5294002f74",
      "name": "获取最新的 n8n 版本",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        144,
        80
      ],
      "parameters": {
        "url": "https://registry.npmjs.org/n8n/latest",
        "options": {
          "fullResponse": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "938334e9-c0b1-476e-a816-4269946d7a41",
      "name": "条件判断",
      "type": "n8n-nodes-base.if",
      "position": [
        864,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a2d169a3-7aa2-46f5-bdb2-f0d53a011b5c",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('Get the latest n8n version').item.json.version }}",
              "rightValue": "={{ $json.versionCli }}"
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": false
    },
    {
      "id": "4802535d-c004-442a-bbd1-610d540e924d",
      "name": "本地 n8n 版本",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        80
      ],
      "parameters": {
        "jsCode": "const text = $input.first().json.data;\nconst match = text.match(/n8n_version_info\\{[^}]*version=\"(v[\\d.]+)\"/);\n\nif (match) {\n  const version = match[1].replace(/^v/, ''); // v entfernen\n  return [{ json: { versionCli: version } }];\n} else {\n  throw new Error(\"Version info not found in metrics output\");\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cee62d71-075b-4bf0-a800-b4fa2fee9ebe",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -16
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "## Cron 定时任务"
      },
      "typeVersion": 1
    },
    {
      "id": "94d2e06e-daf3-4260-929c-584144fbe486",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -16
      ],
      "parameters": {
        "width": 208,
        "height": 272,
        "content": "## 最新版本"
      },
      "typeVersion": 1
    },
    {
      "id": "e1a8d5f8-d672-4475-9ea0-e2eda0028702",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        -16
      ],
      "parameters": {
        "width": 224,
        "height": 272,
        "content": "## 获取指标"
      },
      "typeVersion": 1
    },
    {
      "id": "47c26e66-ba89-4903-a948-22b1162bf1e5",
      "name": "获取本地 n8n 指标",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        368,
        80
      ],
      "parameters": {
        "url": "https://127.0.0.1/metrics",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4bf82532-cc70-4071-83f6-3550392b1590",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        -16
      ],
      "parameters": {
        "width": 224,
        "height": 272,
        "content": "## 已安装版本"
      },
      "typeVersion": 1
    },
    {
      "id": "b11bd405-761f-4328-af3e-0a79c985f654",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -16
      ],
      "parameters": {
        "width": 256,
        "height": 272,
        "content": "## 如果有可用更新"
      },
      "typeVersion": 1
    },
    {
      "id": "559a1933-1bc6-4fc4-bcb2-2ef76364dc0e",
      "name": "便利贴5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        -16
      ],
      "parameters": {
        "width": 256,
        "height": 272,
        "content": "## 开始更新"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1f5d34fd-158e-44a5-8438-f235f4265d00",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Portainer Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get the latest n8n version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "local n8n version": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get local n8n metrics": {
      "main": [
        [
          {
            "node": "local n8n version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the latest n8n version": {
      "main": [
        [
          {
            "node": "Get local n8n metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 开发运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量12
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流