This workflow ensures that your self-hosted n8n workflows are version-controlled in a GitLab repository. It compares each current workflow from n8n with its stored counterpart in GitLab. If any differences are detected, the GitLab file is updated with the latest version.
Retrieve Workflows – Fetch all workflows from the n8n REST API.
Compare with GitLab – For each workflow, fetch the corresponding file from GitLab and compare the JSON.
Update if Changed – If differences exist, commit the updated workflow to GitLab using its API.
Before using the workflow, ensure the following:
n8n: Self-hosted instance with access to the /rest/workflows
API.
GitLab: A repository where workflows will be stored, and a Personal Access Token (PAT) with api
and write_repository
permissions.
n8n Nodes Required:
SplitInBatches
or similar)GITLAB_TOKEN
GITLAB_REPO
GITLAB_BRANCH
(e.g., main
)GITLAB_FILE_PATH_PREFIX
(e.g., n8n-workflows/
)Import the Workflow into your n8n instance.
Configure GitLab API Credentials:
Request node:
Private-Token: {{ $env.GITLAB_TOKEN }}
Map Workflows to GitLab Paths:
n8n-workflows/workflow-name.json
Trigger the Workflow:
Review Commits in GitLab:
"Update workflow: Sample Workflow"