Skip Gitlab Webhook from git or merge request message - gitlab

I have branch, lets called "dev" branch, I attach a webhook to call codemagic build every push/merge request on this branch.
But sometimes, I push/merge request with WIP feature, so I dont want to trigger a webhook when my commit message/merge request message contains "WIP".
Is it possible to do that on gitlab? I don't see any documentation of it.

use [skip ci] inside the commit message or pull request title

Related

Enabling pre-receive server hook to get PR/MR approval before pushing to dev branch

Use case: I have code on my local machine and If I try to push it to remote server, a pre-receive hook in remote [GitLab] server should get triggered and ask for respective author approval to merge that code onto Gitlab repo.
After [code review] if author approves MR then code from my local repo will be pushed to remote server else push needs to be halted.
I am sure that I was asked to enable pre-receive hook on GitLab server side and not on client side.
I think it is not possible because code exists in developer's local machine and hence approver may not be able to do code review but not sure about pre-receive working.
Can pre-receive hook able to notify approver before code push? If it is possible need to know how?
If not, I want a strong valid point to negotiate😒
MR approval is not requested when one pushed a branch, but only when one makes (once the branch is pushed) a merge request to the target branch.
In your case:
protect the dev branch (nobody can push directly to it, so no need for a pre-receive hook)
make a merge request mandatory for that branch
make sure to configure your merge requests so that they must be approved before they can be merged.
That means any code eventually merged to dev:
will not have been pushed directly to dev (MR required)
will have been reviewed and approved first, before being accepted and merged to dev.
While it is true enforcing the MR approval process, meaning disabling the "Merge" button as long as approval is not met, is not free (premium only), you still have a way to enforce it.
Make sure nobody can push/merge to dev is a "Merge Manager" who is alone responsible to merge or not the MRs. If said merge manager sees there is no approval, they won't merge the MR.

Is there a way to get the commit message of the source branch in Gitlab?

Gitlab provides the predefined variable CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, is there a way to get the commit message associated with it?
Please note that I want the commit message of the branch that is merging into another branch. I do not want CI_COMMIT_MESSAGE, that is the commit message for CI_MERGE_REQUEST_TARGET_BRANCH_NAME
The CI_COMMIT_MESSAGE variable will provide the commit message for the commit that triggered the pipeline.
So if you create an MR to merge branch feature/123 into main the CI_COMMIT_MESSAGE var will provide the commit message for the source branch(feature/123)
Gitlab Pre-defined Variables Doc

GitLab CI: MERGE_REQUEST_EVENT not triggered by update?

I'm testing GitLab CI pipelines.
I have created a merge request named "TEST" that have its gitlab-ci.yml with a rule like below:
if '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE == "TEST"'
It worked fine as I expected. Create event triggered the merge_request_event.
However, if I create a merge request have another title and then I update it to "TEST", It doesn't seems to trigger the merge_request_event.
According to this document, merge_request_event is supposed to be triggered by updated too.
For pipelines created when a merge request is created or updated. Required to enable merge request pipelines, merged results pipelines, and merge trains.
Do I take it wrong or missed important information or documents?
Pushing to a branch will trigger a pipeline, and if that branch has an associated Merge Request, then the variable CI_PIPELINE_SOURCE will be equal to merge_request_event.
On the other hand, afaik just editing the title of a Merge Request on the GitLab UI will not trigger a pipeline, so your logic will never be evaluated unless you also push to the branch.
The documentation is correct, but perhaps the meaning is not 100% clear.
For pipelines created when a merge request is created or updated.
Stated more precisely:
When an MR action creates a pipeline, $CI_PIPELINE_SOURCE will be equal to merge_request_event
However, it does not mean to imply that any update will create a pipeline. Updating the MR title does not create a pipeline, so this is not applicable to that scenario.
However, after you have changed the title, if some other event creates a new pipeline (specifically: push events to the MR source branch or manually running a new pipeline on the MR), the rule will evaluate to true and the job will be included in the created pipeline.
Per the docs:
Merge request pipelines:
Run when you:
Create a new merge request.
Push a new commit to the source branch for a merge request.
Select Run pipeline from the Pipelines tab in a merge request.
There appears to be an existing bug with the CI/CD env vars for Merge Requests, where the subsequent pipelines after the initial MR is opened are relegated to push rather than merge_request_event for the CI_PIPELINE_SOURCE.
https://gitlab.com/gitlab-org/gitlab/-/issues/369383#note_1239166213

Gitlab: webhook: merge request event

I have created a webhook in gitlab on a merge request event. And to see what was in the event, I used the ruby example in the docs.
Then I use the test button.
Looking at the json body, I notice that the object kind is "push", even though this is a Merge Request Event. I have other webhooks which are Push events.
The docs for gitlab webhooks show a merge request as having an object kind field of "merge_request". Of course the docs could be out of date.
Any ideas why I appear to be getting push data on a merge request event?
Regards,
John
So the problem is a feature in gitlab. When testing a webhook, it only sends a push event, even if the webhook fires on other events.

github notification to nodeJS when master get a commit

Is it possible if my master branch in my github repo gets an update that my nodeJS server got a notification ? so i can do stuff with it ? like get the version tag and commit message ?
First you need to go to your repo, and click through this sequence:
Settings -> Webhooks & Services -> Add webhook
Then paste the url where github will submit data for each new commit. You can find examples of payload in example.
Then implement the logic needed in the backend to work with info about new commits.

Resources