Fetches workflow definitions from within n8n, selecting only the ones that have one or more (configurable) assigned tags and then:
- Derives a suitable backup filename by reducing the workflow name to a string with alphanumeric characters and no-spaces
- Note: This isn't bulletproof, but works as long as workflow names aren't too crazy.
- Determines which workflows need to be backed up based on whether each one:
- has been modified. (Note: Even repositioning a node counts.)
...or...
- is new. (Note: Renaming counts as this.)
- Commits JSON copies of each workflow, as necessary, to a Gitlab repository with a generated, date-stamped commit message.
Setup
Credentials
- Create a Gitlab Credentials item and assign it to all Gitlab nodes.
- Create an n8n Credentials item and assign it to the n8n node
Modify these values in the "Globals" Node
- gitlab_owner - {{your gitlab account}}
- gitlab_project - {{ your gitlab project name }}
- gitlab_workflow_path - {{ subdirectory in the project where backup files should be saved/committed }}
- tags_to_match_for_backup - {{tag(s) to match for backup selection}}
- ALERT: According to the n8n node's Filters -> tags field annotations, and API documentation, this supports a CSV list of multiple tags (e.g. tag1,tag2), but the API behavior requires workflows to have all-of the listed tags, not any-of them.
- See: https://github.com/n8n-io/n8n/issues/10348
- TL/DR - Don't expect a multiple tag list to be more inclusive.
- Possible workaround: To match more than one tag value, duplicate the n8n node into multiple single-tag matches, or split and iterate multiple values, and merge the results.
Possible Enhancements
- Make the branch ("Reference") for all the gitlab nodes configurable. Fixed on all as "main" in the template.
- Add an n8n node to generate an audit and store the output in gitlab along with the backups.
- Extend the workflow at the end to create a Gitlab release/tag whenever any backup files are actually updated or created.