How can I make GitLab CI run on merge request and after merge?
Two branches, dev and master. Two jobs, test and deploy.
On merge request from any branch to dev branch, CI will trigger. But I only want the test job to run for now. And when the merge request is merged it will then proceed to execute the deploy job. The reason being like this is, although all the tests will pass, we still can't proceed with the deployment because there might be some comments from validators in the Code Review that the dev will need to address. Only after addressing those comments and then if the unit tests are successful will then it be allowed to be merged. After the merge request have been merged, only then will it allow to deploy. The dev branch will be deployed to dev/test and master will be deployed to staging. Prod will be deployed manually.
You can run the pipeline after merge by using Gitlab ci predefined variable $CI_MERGE_REQUEST_APPROVED this will return true after merge has been done and available from gitlab v14. 1. you can add the rule like this in your job.
Yes. The merge request wil update itself to reflect any new commits pushed since it was created, until you finally merge it.
A Git pull request is essentially the same as a Git merge request. Both requests achieve the same result: merging a developer's branch with the project's master or main branch. Their difference lies in which site they are used; GitHub uses the Git pull request, and GitLab uses the Git merge request.
You can revert individual commits or an entire merge request in GitLab.
Use the only
and except
syntax to define the different jobs. If you are merging to your master
branch, you could create a job called before-merge
with the following syntax:
before-merge:
except:
- master
Then, your deploy job runs only for commits to the master branch:
deploy:
only:
- master
This way, the before-merge
job should be executed for commits on all branches except master, and the deploy
job will only be executed after the merge to the master branch occurred.
Reference: https://docs.gitlab.com/ce/ci/yaml/README.html#only-and-except-simplified
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With