'Gtilab pipeline trigger don't work over webhook (returns 404)

I have created a custom trigger form my project in GitLab and it works fine on branch 'main' via curl (with POST queries):

curl -X POST -F token=%myToken% -F ref=main https://%mygitlab%/api/v4/projects/82/trigger/pipeline

OR:

curl --request POST "https://%mygitlab%/api/v4/projects/82/trigger/pipeline?token=%myToken%&ref=main"

But I want to use webhook and try the next:

https://%mygitlab%/api/v4/projects/82/ref/main/trigger/pipeline?token=%myToken%

It doesn't work and returns 404:

{"error":"404 Not Found"}

What do I miss or do wrong? May be I must to configure something?



Solution 1:[1]

Your webhook URL https://%mygitlab%/api/v4/projects/82/ref/main/trigger/pipeline?token=%myToken% should work (use the token from Settings->CI/CD->Pipeline triggers), but the webhook request must be http POST.

This is why

 curl https://%mygitlab%/api/v4/projects/82/ref/main/trigger/pipeline?token=%myToken%

will return 404, but

 curl -X POST https://%mygitlab%/api/v4/projects/82/ref/main/trigger/pipeline?token=%myToken%
 

will work. I have the same behavior on my GitLab (Self-Managed).

Solution 2:[2]

It cannot find it because your repository is not public. You have to add the token parameter to login into your account so it is able to see your repo and succesfully trigger the pipeline.

The token parameter must contain an accessToken you generate in your personal gitlab account. Make sure you gave enough permission to the accessToken.

Also, instead of passing the ref in the url try:

https://gitlab.com/api/v4/projects/82/trigger/pipeline?token=%myToken%&ref=main

Solution 3:[3]

From gitlab's documentation, trigger API doesn't support Personal Access Token. To authenticate, there are two options: Pipeline Trigger Tokens or CI Job tokens.

There is documentation to add a new Pipeline Trigger Token at: https://docs.gitlab.com/ee/ci/triggers/#adding-a-new-trigger

Basically, you have to go to your Settings > CI/CD under Pipelines Triggers to add a new trigger.

From there, you can apply the new token to your curls.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ndu
Solution 2
Solution 3 André Mendonça