Call gitlab API from CI using $CI_JOB_TOKEN fails with access denied

I wish there were an integrated way to call gitlab API from CI script or in some shape and form (to provide input to be saved to pipeline status etc) but there is non as far as I know. So I tried to use curl to do what I need but $CI_JOB_TOKEN does not seem to be valid to execute API calls -I am getting {“message”:“401 Unauthorized”}

I do not want to create a separate user and give it permissions in each project or group not to mention that it is likely that such user key will not be masked like $CI_JOB_TOKEN in job output/logs

or maybe state of the job does not allow such call to be invoked from within the build?

I am doing this:
curl -sS --insecure --request POST --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$CI_PROJECT_ID/statuses/$CI_COMMIT_SHA?state=success&name=$CI_COMMIT_REF_NAME:$B_PROJECT_VERSION-$B_BUILD_NUMBER"

any suggestions?

thank you,

1 Like

I have the same issue. I try using the CI_JOB_TOKEN, but I also get unauthorized error. Does anyone have any feedback on this? Is there a solution that doesn’t involve creating a Personal Access Token?