Problem to solve
Hi, I was trying to setup a CI that will automatically reply the merge request. In order to make it not so verbosely, I want to make it edit the original note if the specific note exists.
I used the GitLab API with project access token, the modification works correctly when I tested it locally. However, with the same project access token in the CI pipeline, the PUT request responds with {"message":"401 Unauthorized"}
.
Since the GET requests and POST requests I used work perfectly fine, I wonder if there’s any restriction on PUT requests in GitLab CI?
Steps to reproduce
if [ "$HAS_REVIEWED" -eq 0 ]; then # Create a new discussion
echo "Creating a new discussion"
curl --request POST --header "PRIVATE-TOKEN: $PAT" \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/discussions?body=$URL_ENCODED_RESPONSE" \
> /dev/null
else # Edit the existing discussion
echo "Editing the existing discussion, note id: $FIRST_NOTE_ID"
curl --request PUT --header "PRIVATE-TOKE: $PAT" \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes/$FIRST_NOTE_ID?body=$URL_ENCODED_RESPONSE"
fi
I have the project access token (PAT
) set in the GitLab CI variable.
The if section creates discussion correctly, but the CI failed to edit the previous note in the else section.
Versions
Please select whether options apply, and add the version information.
- Self-managed
- GitLab.com SaaS
- Self-hosted Runners
Versions
- GitLab (Web:
/help
or self-managed system information): v17.2.0-ee - GitLab Runner, if self-hosted (Web
/admin/runners
or CLIgitlab-runner --version
): 16.7.0 (102c81ba)