Reputation: 2332
I have a job in GitLab CI and I want to set it up to be run under the following conditions.
The reason I'm looking for this type of set up is that the job is extremely long and takes over certain limited resources. Because of that, I don't want the job to run for every commit, only as a last step before a MR is put through. Is it possible to set things up this way?
I'm using GitLab Community Edition 11.7.0.
Upvotes: 3
Views: 1798
Reputation: 4907
Found an option credit to this blog:
Create a job at the last stage of the pipeline (this is only so you get any other relevant job done and reflect a reasonable state)
Prerequisite:
Use case covers OP scenario:
Example yml:
stages:
- first
- cleanup
first-job-only-mr:
stage: first
only:
refs:
- merge_requests
script:
- echo "First job - on Merge request only"
last-job-manual-block-MR:
stage: last
# this is the key config
allow_failure: false
when: manual
only:
refs:
- merge_requests
script:
- echo "Manual job on Merge request only, blocks pipeline if not run, blocking merge"
Upvotes: 0
Reputation: 2758
I don't think that this is possible in GitLab at the moment. They are working on an issue that they call "Prospective merge pipelines" that sounds like what you are searching for:
https://gitlab.com/gitlab-org/gitlab-ee/issues/7380
The work flow they describe is:
As a workaround, you can maybe use "when:manual":
https://docs.gitlab.com/ee/ci/yaml/#whenmanual
Or some other of GitLab CI's feature to only trigger the pipeline manually, and then have as a rule as the users have to paste a link to the pipeline that succeeded before they are allowed to press the merge button.
Upvotes: 1
Reputation: 5644
Yup! GitLab 11.6 introduced pipelines for merge requests. For what you described, I suggest creating a job that is only for merge requests, and not allow failure.
gate:
script: "true"
only:
- merge_requests
allow_failure: false
You'll need to fill in the actual script, job stage, and any other details.
Upvotes: 1