This message was deleted.
# general
b
This message was deleted.
👋 1
b
Hi Aviad! We saw similar issues from other users. CI may use a different token than the one you created. We created this troubleshooting section to catch that case 🙂 https://gitlab.com/infracost/infracost-gitlab-ci#403-error-when-posting-to-gitlab
🚀 1
h
I don't think that's the case, i've changed the name of the token (GITLAB_TOKEN -> GITLAB_INFRACOST_BOT_TOKEN) in purpose to avoid such cases, and notice that I'm getting 401 and not 403 error, that's means I'm not authenticating from the first place and not the case of insufficient permissions.
b
Hm, okay. Next question: do you use self-hosted GitLab with custom domain or the cloud version? If it's self-hosted, you'll have to provide
--gitlab-server-url $CI_SERVER_URL
flag in
infracost comment
command to use its API.
h
cloud version. gitlab.com
🤔 1
b
I assume, you set the
api
scope for the token, right?
h
of course, i've assigned it with all permissions, tried project token and private access token.
b
Sorry, trying to filter out all possibilities 😄
🙌 1
That's strange. To be sure, do you mind verifying that the token is the one you expect? We could generate its checksum and compare with its value, maybe something like
echo $GITLAB_TOKEN | md5sum
Asking, because it happened with several users before after we checked other possibilities as well :)
Additionally to that we could use
curl
with your token and make a direct API request. Let me prepare the command for you.
Copy code
curl -X POST --header "PRIVATE-TOKEN: [token]" --data-urlencode "body=test" <https://gitlab.com/merge_requests/[MR> number]/notes
This will create a new comment on your merge request. I would think if you run it locally, it should work fine, but if you run it in CI, it would fail.
h
should my token contain the name of the token (i.e "PRIVATE-TOKEN") or only the token value?
b
Only the value
h
so what should I replace with PRIVATE-TOKEN? the name of the token?
b
I just realized my example is incomplete (missing project name). I'll provide an example in a second
h
curl -X POST --header "$GITLAB_TOKEN" --data-urlencode "body=test" https://*gi*tlab.com/${CI_PROJECT_PATH}/-/merge_requests/${MR_ID}/notes
b
Copy code
curl -X POST --header "PRIVATE-TOKEN: abc" --data-urlencode "body=test" <https://gitlab.com/api/v4/projects/test%2Frepo/merge_requests/1/notes>
abc - is the value of the token test%2Frepo - should be your repo name in form namespace/project name with encoded slash character 1 - number of the merge request
PRIVATE-TOKEN
is the name of the header, so you need to keep it as
--header "PRIVATE-TOKEN: $GITLAB_TOKEN"
@helpful-france-46557 Have you had a chance to try the API request?
Hi @helpful-france-46557! Just checking in to see if you've been able to to resolve the issue 🙂