Reputation: 2294
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?
Upvotes: 13
Views: 6460
Reputation: 333
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:
If you still have problems and you have access to the gitlab server logs, I would look there.
Upvotes: 0
Reputation: 3032
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.
Upvotes: -1
Reputation: 8852
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.
Upvotes: 19
Reputation: 2294
I retried the same request today, now it works. Probably there has been some problem with the gitlab.com.
Upvotes: 0