Tadeusz
Tadeusz

Reputation: 6883

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?

Upvotes: 0

Views: 3413

Answers (3)

ndu
ndu

Reputation: 176

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).

Upvotes: 2

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.

Upvotes: 0

Robert-Jan Kuyper
Robert-Jan Kuyper

Reputation: 3306

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

Upvotes: 0

Related Questions