使用AI将n8n工作流备份到GitLab
中级
这是一个DevOps, AI Summarization领域的自动化工作流,包含 15 个节点。主要使用 If, N8n, Code, Gitlab, N8nTrigger 等节点。 基于GPT-4.1文档生成的自动工作流备份至GitLab
前置要求
- •GitLab Personal Access Token
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "jzbnQsF9eV0G8PKA",
"meta": {
"instanceId": "a28fa941f4dd50ba130162204d368b9dfd7d9b960d864f7ae0094ae8b516daa8",
"templateCredsSetupCompleted": true
},
"name": "使用 AI 将 n8n 工作流备份到 GitLab",
"tags": [],
"nodes": [
{
"id": "3e71ace2-735e-47c8-a9c0-23c575080f47",
"name": "如果",
"type": "n8n-nodes-base.if",
"position": [
560,
-336
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "db9435fd-f5b4-4c18-a9a2-0b6471c029e8",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.isFileOnGit }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "d5316aa4-c279-4eec-a7af-c10e0ed663f8",
"name": "当由另一个工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-336,
-432
],
"parameters": {
"inputSource": "passthrough"
},
"typeVersion": 1.1
},
{
"id": "5b647f82-91ee-43d2-be81-72f615d7cae3",
"name": "工作流变更检测器",
"type": "n8n-nodes-base.n8nTrigger",
"position": [
-336,
-240
],
"parameters": {
"events": [
"update",
"activate"
]
},
"typeVersion": 1
},
{
"id": "12c58db0-c097-444e-ace7-6d7492547130",
"name": "获取更新的工作流",
"type": "n8n-nodes-base.n8n",
"position": [
-112,
-336
],
"parameters": {
"operation": "get",
"workflowId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.workflow_id }}"
},
"requestOptions": {}
},
"credentials": {
"n8nApi": {
"id": "sPrxjiTGmum0YltE",
"name": "n8n account"
}
},
"typeVersion": 1
},
{
"id": "5b6307b5-bef1-4064-93d5-8651585dccc2",
"name": "检查 GitLab 仓库",
"type": "n8n-nodes-base.gitlab",
"onError": "continueRegularOutput",
"position": [
112,
-336
],
"parameters": {
"owner": "n8n_projects",
"filePath": "={{$json.name +'/' }}",
"resource": "file",
"operation": "list",
"returnAll": true,
"repository": "all_projects",
"additionalParameters": {}
},
"credentials": {
"gitlabApi": {
"id": "jSe8yMHXlJPNv5lh",
"name": "GitLab account"
}
},
"typeVersion": 1
},
{
"id": "cdce94a6-bb32-4ab5-b6fa-d32a13706cbb",
"name": "分析仓库状态",
"type": "n8n-nodes-base.code",
"position": [
336,
-336
],
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nconst err = $input.first().json.error;\nif(err\n && err.indexOf(\"resource you are requesting could not be found\")>0)\n return {workflow: $('Fetch Updated Workflow').first().json,isFileOnGit:false};\n\nlet isFileOnGit = false;\nfor (const item of $input.all()) {\n if(item.json.name == $('Fetch Updated Workflow').first().json.name +\".json\"){\n isFileOnGit = true;\n break;\n }\n}\n\nreturn {workflow: $('Fetch Updated Workflow').first().json,isFileOnGit};"
},
"typeVersion": 2
},
{
"id": "4db0954c-e7f3-45af-892d-b7befd983539",
"name": "更新现有工作流",
"type": "n8n-nodes-base.gitlab",
"position": [
784,
-432
],
"parameters": {
"owner": "n8n_projects",
"branch": "main",
"filePath": "={{ $('Analyze Repository State').item.json.workflow.name+'/'+$('Analyze Repository State').item.json.workflow.name +\".json\"}}",
"resource": "file",
"operation": "edit",
"repository": "all_projects",
"fileContent": "={{ $('Analyze Repository State').item.json.workflow.toJsonString() }}",
"commitMessage": "={{ `updated by n8n` }}"
},
"credentials": {
"gitlabApi": {
"id": "jSe8yMHXlJPNv5lh",
"name": "GitLab account"
}
},
"typeVersion": 1
},
{
"id": "d5595a4d-e56e-4d97-a794-68bb09c6bdd8",
"name": "创建新工作流文件",
"type": "n8n-nodes-base.gitlab",
"position": [
784,
-240
],
"parameters": {
"owner": "n8n_projects",
"branch": "main",
"filePath": "={{$('Analyze Repository State').item.json.workflow.name+'/'+ $('Analyze Repository State').item.json.workflow.name +\".json\"}}",
"resource": "file",
"repository": "all_projects",
"fileContent": "={{$json.workflow.toJsonString()}}",
"commitMessage": "Pushed by n8n"
},
"credentials": {
"gitlabApi": {
"id": "jSe8yMHXlJPNv5lh",
"name": "GitLab account"
}
},
"typeVersion": 1
},
{
"id": "4cde1c01-7294-493d-908a-adeca486c213",
"name": "生成 AI 文档",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
1008,
-240
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1",
"cachedResultName": "GPT-4.1"
},
"options": {},
"messages": {
"values": [
{
"content": "=Generate a simple readme.md for the following n8n workflow json.\nYour json output must be exaclty this:\n{\"README\":\"The markdown content\"}\nWorkflow JSON:\n\n{{ $('Analyze Repository State').item.json.workflow.toJsonString() }}"
}
]
},
"jsonOutput": true
},
"credentials": {
"openAiApi": {
"id": "OLXWXsZdKGOvJr95",
"name": "OpenAi account"
}
},
"typeVersion": 1.8
},
{
"id": "a8471cd5-0619-44cd-ae4e-e07dba2b87fa",
"name": "保存 README 到 GitLab",
"type": "n8n-nodes-base.gitlab",
"position": [
1408,
-240
],
"parameters": {
"owner": "n8n_projects",
"branch": "main",
"filePath": "={{$('Analyze Repository State').item.json.workflow.name+'/readme.md'}}",
"resource": "file",
"repository": "all_projects",
"fileContent": "={{ $json.message.content.README }}",
"commitMessage": "Pushed by n8n"
},
"credentials": {
"gitlabApi": {
"id": "jSe8yMHXlJPNv5lh",
"name": "GitLab account"
}
},
"typeVersion": 1
},
{
"id": "80f77f85-0766-4107-83b2-57e2d4cb9d73",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-496,
-848
],
"parameters": {
"width": 480,
"height": 416,
"content": "**使用 AI 生成的文档自动将 n8n 工作流备份到 GitLab**"
},
"typeVersion": 1
},
{
"id": "18b73c77-f66c-4bb7-82be-0ec51d6f488d",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
64,
-400
],
"parameters": {
"color": 7,
"width": 424,
"height": 224,
"content": "检索工作流数据并检查仓库状态以确定文件是否存在于仓库中"
},
"typeVersion": 1
},
{
"id": "a032531b-7e75-4c53-8abf-c259c55ea10e",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-496,
-272
],
"parameters": {
"color": 7,
"height": 80,
"content": "在工作流更新或激活时触发"
},
"typeVersion": 1
},
{
"id": "538be132-53e5-424c-afdd-d74f7dcd282b",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
544,
-512
],
"parameters": {
"color": 7,
"width": 400,
"height": 480,
"content": "在 GitLab 中创建或更新工作流文件"
},
"typeVersion": 1
},
{
"id": "796de781-25ef-42a4-a17f-6ffc350e4aeb",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
976,
-320
],
"parameters": {
"color": 7,
"width": 312,
"height": 288,
"content": "使用 OpenAI 自动生成 README 文件"
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "8b4b37e5-d7f5-4c32-84c8-90d1fa120a8a",
"connections": {
"If": {
"main": [
[
{
"node": "Update Existing Workflow",
"type": "main",
"index": 0
}
],
[
{
"node": "Create New Workflow File",
"type": "main",
"index": 0
}
]
]
},
"Fetch Updated Workflow": {
"main": [
[
{
"node": "Check GitLab Repository",
"type": "main",
"index": 0
}
]
]
},
"Check GitLab Repository": {
"main": [
[
{
"node": "Analyze Repository State",
"type": "main",
"index": 0
}
]
]
},
"Analyze Repository State": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Create New Workflow File": {
"main": [
[
{
"node": "Generate AI Documentation",
"type": "main",
"index": 0
}
]
]
},
"Workflow Change Detector": {
"main": [
[
{
"node": "Fetch Updated Workflow",
"type": "main",
"index": 0
}
]
]
},
"Generate AI Documentation": {
"main": [
[
{
"node": "Save README to GitLab",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Fetch Updated Workflow",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 开发运维, AI 摘要总结
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
UniFi控制器:检查并在新发布时升级
通过SSH和Telegram通知自动化UniFi控制器更新
If
Ssh
Code
+5
11 节点Dominic Spatz
开发运维
自动化n8n工作流备份至GitHub并追踪删除
自动化n8n工作流备份至GitHub并追踪删除
If
N8n
Set
+13
31 节点Marcial Ambriz
开发运维
Telegram自动复制器
基于GPT-4o-mini的Telegram频道内容自动复制与翻译
If
Set
Code
+6
19 节点Shohani
社交媒体
Telegram-n8n-指挥官
通过 Telegram 机器人命令远程控制 n8n 实例
If
N8n
Set
+11
67 节点Arthur Braghetto
开发运维
使用GPT和TTS通过WhatsApp将网站转换为音频摘要
使用GPT和TTS通过WhatsApp将网站转换为音频摘要
If
Set
Code
+13
23 节点Anthony
个人效率
GitHub 同步仪表板 - V2
具有提交历史和回滚功能的 GitHub 工作流版本控制仪表板
If
N8n
Set
+20
94 节点Eduard
开发运维