At ioxp we automate our continuous integration using the awesome Gitlab project. However, their model of when testing jobs run on commits induced quite a heavy load on our testing servers. So we were very delighted when pipelines for merge requests were introduced in Gitlab 11.6.
We then configured our testing to run with
However, our development process (more on that in a later post) recommends:
If a developer starts working on an issue, they have to
1. (if not already done) assign them
2. Create a branch starting with their two-letter initials, like
3. Open a new WIP merge request mentioning the issue to mark that it is currently being worked on. As the Merge Request window even offers a small button to automatically append this prefix, the workflow is quite easy here.
4. Assign themselves to the merge request because they are currently responsible for it
We do this to have a nice overview about what is currently going on and to discuss about unfinished work. However, our only:merge_requests became useless now – as every implementation starts with a merge request, the pipelines are immediately started wasting CI time.
Luckily, variables expressions came to our rescue:
integrationtest: stage: integrationtest tags: - withBackend only: - merge_requests except: variables: - $CI_MERGE_REQUEST_TITLE =~ /^WIP:.*/
It is as easy as that. The expression filters the merge requests by their title and the job only runs when it does not start with the WIP prefix.
Update: Newer GitLab versions use the “Draft:” prefix instead of “WIP:” by default, so to support both notations, the script needs to make use of the OR operator like this:
stage: integrationtest tags: - withBackend only: - merge_requests except: variables: - $CI_MERGE_REQUEST_TITLE =~ /^WIP:.*/ || $CI_MERGE_REQUEST_TITLE =~ /^Draft:.*/