The Simplest Way to Make GitLab CI and Mercurial Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair gitlab ci and mercurial to run automated builds on legacy codebases. A bridge syncs commits or triggers runners to pull source files and test them. Many older projects still live in Mercurial servers. Modern build teams want to use GitLab pipelines for testing and shipping. Linking both tools lets engineers keep their version history while using modern build runners. This setup works well when teams cannot move all their code at once. How data and keys flow between gitlab ci and me

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair gitlab ci and mercurial to run automated builds on legacy codebases. A bridge syncs commits or triggers runners to pull source files and test them.

Many older projects still live in Mercurial servers. Modern build teams want to use GitLab pipelines for testing and shipping. Linking both tools lets engineers keep their version history while using modern build runners. This setup works well when teams cannot move all their code at once.

How data and keys flow between gitlab ci and mercurial

GitLab runners expect Git repos by default. To work with Mercurial, you must set up a custom sync or fetch step. First, a developer pushes a new change to the Mercurial server. Next, a webhook tells the GitLab pipeline to start a new job.

Some teams use a mirror tool that converts Mercurial commits into Git commits. The mirror pushes these changes into a blank GitLab project. Then the runner starts its job using standard pipeline rules. Other teams tell the runner to skip the default clone step. Instead, the build job uses a custom script to pull directly from Mercurial.

Both paths need a way to log in and read the source code. The runner uses an SSH key or an API token to prove its identity. The Mercurial server checks this key against its user list. If the key is valid, the server sends the code to the runner. Once the test finishes, the runner sends the status back to the pipeline.

Common failure modes and how to scope roles

Shared service accounts cause the biggest security gaps in this workflow. Teams often make one admin account on the Mercurial server for all builds. They put that single static key into many project settings. If one build script leaks the key, an attacker can read or change every repo.

Broad tokens also break your audit logs. When ten pipelines share one login, the server log shows one user for everything. You cannot tell which job pulled code or pushed a tag. Unlogged pulls make security reviews very hard during an incident.

GitLab CI Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, give each pipeline its own read-only role. Never let a test runner use a key that can write to main branches. If a job only runs unit tests, it only needs read rights. Create separate keys for each project so you can revoke them one by one.

You should also lock down network paths between the two systems. Put your runners in a private subnet with strict firewall rules. Only allow the runner IP range to talk to the Mercurial server port. Block all public traffic from reaching your internal code host. Rotate your build keys on a set schedule to limit the risk of leaks.

Keeping build runners fast and clean

Large Mercurial histories can slow down your build jobs if you pull everything. Tell your runner scripts to fetch only the specific revision needed for the test. Clean up the workspace folder after every run so old files do not remain. Make sure your error logs mask sensitive fields like emails or phone numbers. This keeps your build output safe while giving developers clear feedback on failed tests.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can GitLab runners pull Mercurial code without a Git mirror?

Yes, you can turn off the default Git clone step in your job settings. The runner can then install the Mercurial client and pull the target revision directly.

How should we restrict runner keys on the Mercurial server?

Grant each runner a dedicated account with read-only permissions on one specific repo. Do not share admin keys or write tokens across multiple build pipelines.

What is the safest way to trigger builds from Mercurial commits?

Use an outgoing commit hook on your Mercurial server to call the pipeline webhook. Send only the commit hash and branch name over an encrypted network path.

The query runs. The emails stay hidden.