Reputation: 29
I am trying to trigger a pipeline using $CI_JOB_TOKEN. But it gives a 404 error everytime. Is there somebody could block CI_JOB_TOKEN from triggering a pipeline ?? at access levels ??
curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.eample.com/api/v4/projects/73237/trigger/pipeline
Upvotes: 2
Views: 2112
Reputation: 11
For me the answer was to allow the triggering project access by navigating to the target project's CI/CD settings, go to "Job Token Permissions", then add the path of the project that is the one doing the triggering.
Upvotes: 0
Reputation: 846
For me using the CI_JOB_TOKEN also returned a 404 error for a private repository. When I instead executed the same command using a pipeline trigger token (Settings > CI/CD/ Pipeline triggers
) it works as expected.
A similar problem is described in this issue https://gitlab.com/gitlab-org/gitlab/-/issues/17511
Just for clarification: You have to generate the token in the other project and then set it as a custom ci variable e.g. PIPELINE_TRIGGER_TOKEN
in the project where you want to use it. Then in the curl request within .gitlab-ci.yml
replace CI_JOB_TOKEN
with PIPELINE_TRIGGER_TOKEN
.
Upvotes: 2
Reputation: 1328992
Check also your GitLab version:
With GitLab 14.1 (July 2021), you have:
Default branch name redirect
Default branch name redirect
As part of the larger effort to rename Git’s default initial branch in a GitLab project from
master
tomain
, we are adding an automatic redirect to streamline the transition. Previously, when projects renamed the default branch, current URLs would result in404 Not Found
. This is a frustrating experience when you are trying to navigate between branches. Now, if you navigate to a file or directory path whose default branch was renamed, you will be redirected to the updated path automatically.See Documentation and Issue.
So your problem might not exist with 14.1.
Upvotes: -1
Reputation: 207
Could you please make sure the ref=master
is correct? Recently master
was changed to main
your API call might be hitting a non-existent branch hence 404
Upvotes: 0