GitLab API

GitlabTool

Actions1000

Overview

This node operation allows users to protect a specific branch in a GitLab project by making a PUT request to the GitLab API endpoint `/api/v4/projects/{id}/repository/branches/{branch}/protect`. It is useful for scenarios where you want to enforce branch protection rules such as preventing force pushes or deletions on important branches in a repository. For example, a DevOps engineer might use this node to programmatically protect the main or release branches in multiple projects to ensure code stability and compliance.

Use Case Examples

  1. Protect the 'main' branch of a project with ID '123' to prevent unauthorized changes.
  2. Automate branch protection for release branches across multiple GitLab projects in a CI/CD pipeline.

Properties

Name Meaning
Skip Authentication Whether to skip authentication for the API request (boolean). Useful for testing or public endpoints.
Authentication The authentication method used for the API request, defaulting to GitLab API key authentication.
baseUrl The base URL of the GitLab instance, defaulting to https://gitlab.com.
Method The HTTP method to use for the request, defaulting to PUT for this operation.
Path Parameters Parameters to specify the project ID and branch name to protect.

Output

JSON

  • id - The ID or URL-encoded path of the project used in the request
  • branch - The name of the branch being protected
  • protectionStatus - The result or status of the branch protection operation, typically returned by the GitLab API

Dependencies

  • GitLab API key credential for authentication

Troubleshooting

  • Ensure the project ID and branch name are correctly specified and URL-encoded if necessary.
  • Verify that the API key used has sufficient permissions to protect branches in the specified project.
  • Check the base URL to ensure it points to the correct GitLab instance, especially if using a self-hosted GitLab server.
  • Common error messages may include authentication failures, permission denied errors, or invalid project/branch identifiers. Resolving these typically involves verifying credentials, permissions, and input parameters.

Links

Discussion