Skip to main content

Automate GitLab merge requests using APIs with n8n

Workflow preview

Workflow preview
100%
Automate GitLab merge requests using APIs with n8n preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Who is this template for? This template is designed for developers, DevOps engineers, and automation enthusiasts who want to streamline their GitLab merge request process using n8n, a low code work...

Best for

  • DevOps automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.httprequest, n8n-nodes-base.if, n8n-nodes-base.splitinbatches, n8n-nodes-base.wait, n8n-nodes-base.set, n8n-nodes-base.scheduletrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Aditya Gaur.

Original n8n.io source

1.1 Workflow description

Title
Automate GitLab merge requests using APIs with n8n
Workflow name
Automate GitLab merge requests using APIs with n8n

Who is this template for?

This template is designed for developers, DevOps engineers, and automation enthusiasts who want to streamline their GitLab merge request process using n8n, a low-code workflow automation tool. It eliminates manual intervention by automating the merging of GitLab branches through API calls.

How it works ?

  • Trigger the workflow: The workflow can be triggered by a webhook, a scheduled event, or a GitLab event (e.g., a new merge request is created or approved).

  • Fetch Merge Request Details: n8n makes an API call to GitLab to retrieve merge request details.

  • Check Merge Conditions: The workflow validates whether the merge request meets predefined conditions (e.g., approvals met, CI/CD pipelines passed).

  • Perform the Merge: If all conditions are met, n8n sends a request to the GitLab API to merge the branch automatically.

Setup Steps

1. Prerequisites

An n8n instance (Self-hosted or Cloud)

A GitLab personal access token with API access

A GitLab repository with merge requests enabled

2. Create the n8n Workflow

Set up a trigger: Choose a trigger node (Webhook, Cron, or GitLab Trigger).

Fetch merge request details: Add an HTTP Request node to call GET /merge_requests/:id from GitLab API.

Validate conditions:

Check if the merge request has necessary approvals.

Ensure CI/CD pipelines have passed.

Merge the request:

Use an HTTP Request node to call PUT /merge_requests/:id/merge API.

3. Test the Workflow

Create a test merge request.

Check if the workflow triggers and merges automatically.

Debug using n8n logs if needed.

4. Deploy and Monitor

Deploy the workflow in production.

Use n8n’s monitoring features to track execution.

This template enables seamless GitLab merge automation, improving efficiency and reducing manual work!

Note:

Never hard code API token or secret in your https request.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - API to Check existing merge request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 2 - Is Exists

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 3 - Create New Merge Request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 4 - Loop Over Items

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 5 - API to CLOSE existing Merge Request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 6 - Add Custom Notes To Merge Request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 7 - 30 secs wait to approve merge request and pipeline to finish1

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 8 - Merge When Pipeline Succeeds

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 9 - setValueForMerge

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 10 - Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

3. Summary Table

Workflow Automate GitLab merge requests using APIs with n8n
Complexity intermediate
Nodes 10
Categories DevOps
Author Aditya Gaur
Published 07 Feb 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2858/2858.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automate GitLab merge requests using APIs with n8n do?

Who is this template for? This template is designed for developers, DevOps engineers, and automation enthusiasts who want to streamline their GitLab merge request process using n8n, a low code work...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your DevOps use case.