Manually triggering ‘merge-only’ workflows in Gitlab

George Shuklin
OpsOps
Published in
1 min readMay 11, 2021

I don’t like to write about proprietary software (which Gitlab, mostly, is). Nevertheless, the pain and discomfort is there, so, I’m writing down clever tricks of avoiding pain.

The problem

Some CI jobs are so long and complicated, that they worth been run only on merge request.

It’s usually done by this statement in job definition:

rules:
- if: $CI_MERGE_REQUEST_ID

The consequence of that is job in pipeline is run only if it’s part of the merge request.

But there is an occasional need to run it without merge request. The most often case is to cause cleanup code to do it’s job, or to test if a new hardware for that CI is operational.

Creating fake merge requests is bad. There is a better solution. Just set

CI_MERGE_REQUEST_ID = -1

before running pipeline, and it would acts like it’s in the middle of merge request.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.