Gitlab Trigger API returns 404
Asked Answered
A

4

13

I created a trigger (using settings/ci_cd page). The instructions below the trigger tell me to call it using version 3 API (of course, I set the token variable to the token stated under the trigger section):

curl -X POST \
     -F token=${TOKEN} \
     -F ref=master \
     https://gitlab.com/api/v3/projects/2313008/trigger/builds

Which only returns:

{"error":"404 Not Found"}

I also tried to follow the API v4 documentation:

curl --request POST \
     --form token=${TOKEN} \
     --form ref=master \
     https://gitlab.com/api/v4/projects/2313008/trigger/pipeline

which returns the same error.

Are there any additional settings required?

Angelia answered 12/3, 2017 at 11:8 Comment(3)
Are you sure you have set the token variable?Diddle
Yes, I am. Also I would expect to get some other Error then 404.Angelia
Well, 404 is pretty clever taken you don't want someone to enumerate the projects you have on your machine.Diddle
A
17

I had the same issue, but I was using Personal Access Token instead of Pipeline trigger token!!

You can generate this token inside your project repo CI/CD settings. Pipeline triggers

Asymmetric answered 6/2, 2018 at 13:41 Comment(0)
A
0

I retried the same request today, now it works. Probably there has been some problem with the gitlab.com.

Angelia answered 9/4, 2017 at 8:43 Comment(0)
A
0

I would first make sure you're using the latest version of the API, which is v4. The endpoint to use to trigger a pipeline is:

POST /projects/:id/trigger/pipeline 

Next up, you will want to ensure you have the correct project ID in the API URL. You can get this by going to your project's page on GitLab and looking at the URL. It should look something like:

https://gitlab.com/username/project-name 

The project ID is that number that pops up when you hover over the project name.

You will want to make sure you have the correct trigger token. You can create a new trigger token by going to your project's Settings > CI/CD > Pipeline Triggers. Be sure to remember to keep that token safe and not share it with the world.

When you're ready to make the API call, make sure you're sending the correct parameters (token and ref) as form data. Here's a simple example in cURL:

curl --request POST \ 
--form token=YOUR_TRIGGER_TOKEN \ 
--form ref=main \ 
https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/trigger/pipeline 

Remember to replace YOUR_TRIGGER_TOKEN with your actual trigger token and YOUR_PROJECT_ID with your project ID.

I saw this problem the other day. The last thing to mention is to double-check that you're using the trigger token and not mixing it with a personal access token. The trigger token is specifically designed for triggering pipelines, while a personal access token is used for authentication when working with the GitLab API.

If you've double-checked all of the above and you're still seeing a 404 error, it could be due to a few reasons:

  • The project ID might be incorrect, or the project doesn't exist.
  • The trigger token might be invalid or has been revoked.
  • You might not have the right permissions to trigger a pipeline for the specified project.

If you still have problems and you have access to the gitlab server logs, I would look there.

Albuminuria answered 26/4 at 11:36 Comment(0)
D
-1

Don't forget that you have to use CURL for this. Pasting it on the browser will result 404. Perhaps this is because of CORS.

Dehydrogenate answered 19/4 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.