Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run GitlabCI during Merge Request and After Merge

Tags:

gitlab-ci

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.

like image 206
Karias Bolster Avatar asked Jul 23 '18 09:07

Karias Bolster


People also ask

How do I run a pipeline after merge?

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.

Can I push after merge request?

Yes. The merge request wil update itself to reflect any new commits pushed since it was created, until you finally merge it.

Is GitLab merge request same as pull request?

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.

Can you reopen a merge request GitLab?

You can revert individual commits or an entire merge request in GitLab.


1 Answers

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

like image 197
Philipp Ludwig Avatar answered Nov 07 '22 15:11

Philipp Ludwig