GitLab node
+5

Backup Tag-Selected Workflows to Gitlab

Published 3 months ago

Created by

hubschrauber
Hubschrauber

Categories

Template description

Fetches workflow definitions from within n8n, selecting only the ones that have one or more (configurable) assigned tags and then:

  1. 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.
  2. 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.)
  3. 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.

Share Template

More DevOps workflow templates

Git backup of workflows and credentials

This creates a git backup of the workflows and credentials. It uses the n8n export command with git diff, so you can run as many times as you want, but only when there are changes they will create a commit. Setup You need some access to the server. Create a repository in some remote place to host your project, like Github, Gitlab, or your favorite private repo. Clone the repository in the server in a place that the n8n has access. In the example, it's the ., and the repository name is repo. Change it in the commands and in the workflow commands (you can set it as a variable in the wokflow). Checkout to another branch if you won't use the master one. cd . git clone repository Or you could git init and then add the remote (git remote add origin YOUR_REPO_URL), whatever pleases you more. As the server, check if everything is ok for beeing able to commit. Very likely you'll need to setup the user email and name. Try to create a commit, and push it to upstream, and everything you need (like config a user to comit) will appear in way. I strong suggest testing with exporting the commands to garantee it will work too. cd ./repo git commit -c "Initial commmit" --allow-empty -u is the same as --set-upstream git push -u origin master Testing to push to upstream with the first exported data npx n8n export:workflow --backup --output ./repo/workflows/ npx n8n export:credentials --backup --output repo/credentials/ cd ./repo git add . git commit -c "manual backup: first export" git push After that, if everything is ok, the workflow should work just fine. Adjustments Adjust the path in used in the workflow. See the the git -C PATH command is the same as cd PATH; git .... Also, adjust the cron to run as you need. As I said in the beginning, you can run it even for every minute, but it will create commits only when there are changes. Credentials encryption The default for exporting the credentials is to do them encrypted. You can add the flag --decrypted to the n8n export:credentials command if you need to save them in plain. But as general rule, it's better to save the encryption key, that you only need to do that once, and them export it safely encrypted.
allandaemon
Allan Daemon
Google Sheets node
HTTP Request node
Slack node
+4

Host your own Uptime Monitoring with Scheduled Triggers

This n8n workflow demonstrates how to build a simple uptime monitoring service using scheduled triggers. Useful for webmasters with a handful of sites who want a cost-effective solution without the need for all the bells and whistles. How it works Scheduled trigger reads a list of website urls in a Google Sheet every 5 minutes Each website url is checked using the HTTP node which determines if the website is either in the UP or DOWN state. An email and Slack message are sent for websites which are in the DOWN state. The Google Sheet is updated with the website's state and a log created. Logs can be used to determine total % of UP and DOWN time over a period. Requirements Google Sheet for storing websites to monitor and their states Gmail for email alerts Slack for channel alerts Customising the workflow Don't use Google Sheets? This can easily be exchanged with Excel or Airtable.
jimleuk
Jimleuk
Merge node
Webhook node
+10

πŸ¦… Get a bird's-eye view of your n8n instance with the Workflow Dashboard!

Using n8n a lot? Soar above the limitations of the default n8n dashboard! This template gives you an overview of your workflows, nodes, and tags – all in one place. πŸ’ͺ Built using XML stylesheets and the Bootstrap 5 library, this workflow is self-contained and does not depend on any third-party software. πŸ™Œ It generates a comprehensive overview JSON that can be easily integrated with other BI tools for further analysis and visualization. πŸ“Š Reach out to Eduard if you need help adapting this workflow to your specific use-case! πŸš€ Benefits: Workflow Summary** πŸ“ˆ: Instant overview of your workflows, active counts, and triggers. Left-Side Panel** πŸ“‹: Quick access to all your workflows, nodes, and tags for seamless navigation. Workflow Details** πŸ”¬: Deep dive into each workflow's nodes, timestamps, and tags. Node Analysis** 🧩: Identify the most frequently used nodes across your workflows. Tag Organization** πŸ—‚οΈ: Workflows are grouped according to their tags. Visually Stunning** 🎨: Clean, intuitive, and easy-to-navigate dashboard design. XML & Bootstrap 5** πŸ› οΈ: Built using XML stylesheets and Bootstrap 5, ensuring a self-contained and responsive dashboard. No Dependencies** πŸ”’: The workflow does not rely on any third-party software. Bootstrap 5 files are loaded via CDN but can be delivered directly from your server. ⚠️ Important note for cloud users Since the cloud version doesn't support environmental variables, please make the following changes: get-nodes-via-jmespath node. Update the instance_url variable: enter your n8n URL instead of {{$env["N8N_PROTOCOL"]}}://{{$env["N8N_HOST"]}} Create HTML node. Please provide the n8n instance URL instead of {{ $env.WEBHOOK_URL }} 🌟Example: Check out our other workflows: n8n.io/creators/eduard n8n.io/creators/yulia
eduard
Eduard

Implement complex processes faster with n8n

red icon yellow icon red icon yellow icon