Auto Backup n8n Workflows to GitLab with AI-Generated Documentation
Trigger detects workflow changes → fetch JSON → check GitLab repo → create or update file → GPT-4.1 generates README → push to repository
- Who
- Developers or teams using n8n for automation ops who need version-controlled workflows with auto-generated docs
- You get
- When a workflow is updated or activated, automatically back up its JSON to GitLab and generate a matching README
Constraints
Prerequisites: accessible n8n instance; GitLab repository (default name 'all_projects') and a personal access token with write permissions; OpenAI API key. Cost: OpenAI API billed by token usage; GitLab typically within free tier limits.
What they did
Author shohani published this workflow template on n8n.io. The template detects workflow changes via n8n Trigger or Execute Workflow Trigger, fetches workflow JSON via the n8n API, checks GitLab for an existing file, creates or updates it, then calls OpenAI GPT-4.1 to generate a README and pushes both files to GitLab.
How it went
The template is published on n8n.io with 779 views at time of collection (author_report). This site has not tested runtime behavior.
Worth knowing
The template defaults to GPT-4.1, but gpt-4 is also listed in the model options and can be selected in the node. It can be used as a sub-workflow inside other workflows. The default repository name is 'all_projects' and must be changed manually. The comment in the Code node is leftover default text from n8n's template generator and does not describe the actual logic. OpenAI output must be strict JSON; malformed output will cause the downstream node to fail.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Fetch Updated Workflow node: connect n8nApi credentials.
- Check GitLab Repository node: connect gitlabApi credentials.
- Update Existing Workflow node: connect gitlabApi credentials.
- Create New Workflow File node: connect gitlabApi credentials.
- Generate AI Documentation node: connect OpenAI API credentials.
- Save README to GitLab node: connect gitlabApi credentials.
Configuration to replace
- Source template is n8n public workflow #6731 (~15 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-24
Steps
Import template and configure credentials
Import template 6731 in n8n. Configure credentials in each node: GitLab (gitlabApi, needs personal access token), n8n API (n8nApi, for fetching workflow data), and OpenAI (openAiApi, for documentation generation). Update the owner and repository fields in GitLab nodes to match your setup (defaults: owner='n8n_projects', repository='all_projects').
Set triggers and fetch workflow data
The template provides two triggers: the n8n Trigger node (Workflow Change Detector) listens for workflow update and activate events; the Execute Workflow Trigger node (When Executed by Another Workflow) allows being called by other workflows. Upon trigger, the Fetch Updated Workflow node retrieves the full workflow JSON via the n8n API.
Check GitLab repository state
The Check GitLab Repository node lists files at the specified path (with onError='continueRegularOutput' to handle non-existent directories). The Analyze Repository State node runs code to determine: if the error contains 'resource you are requesting could not be found', or if no matching .json file exists, mark isFileOnGit=false; otherwise mark true.
Execution prompt · Source text。JS Code field of the Analyze Repository State node
// Loop over input items and add a new field called 'myNewField' to the JSON of each one const err = $input.first().json.error; if(err && err.indexOf("resource you are requesting could not be found")>0) return {workflow: $('Fetch Updated Workflow').first().json,isFileOnGit:false}; let isFileOnGit = false; for (const item of $input.all()) { if(item.json.name == $('Fetch Updated Workflow').first().json.name +".json"){ isFileOnGit = true; break; } } return {workflow: $('Fetch Updated Workflow').first().json,isFileOnGit};Create or update workflow file
The If node branches on isFileOnGit: if true, route to Update Existing Workflow to edit the existing .json file; if false, route to Create New Workflow File to create it. File path format is {workflow_name}/{workflow_name}.json, committed to the main branch.
Generate AI documentation and save README
After creating the workflow file, the Generate AI Documentation node calls OpenAI GPT-4.1 with the workflow JSON and requests a README. Output must be strict JSON: {"README":"markdown content"}. The Save README to GitLab node then extracts message.content.README and saves it as {workflow_name}/readme.md.
Execution prompt · Source text。messages.values[0].content field of the Generate AI Documentation node
=Generate a simple readme.md for the following n8n workflow json. Your json output must be exaclty this: {"README":"The markdown content"} Workflow JSON: {{ $('Analyze Repository State').item.json.workflow.toJsonString() }}
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions first
This block is the prompt. Ads are never placed here.
You are recreating n8n template 6731: auto-backup workflows to GitLab with GPT-4.1-generated READMEs. First confirm you have an n8n instance, a GitLab personal access token (write access), and an OpenAI API key. After importing the template, configure the three credential types and update the GitLab node's owner and repository to your actual values. Test by triggering an update on a dummy workflow and verify both JSON and readme.md appear in GitLab.
Nodes will error if credentials are missing; default GitLab owner is 'n8n_projects' and must be changed to your username or organization
Source
Automatic workflow backups to GitLab with GPT-4.1 documentation generation · shohani · n8n.io · 2025-07-31
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.