I'm trying to use GLab in a pipeline to create a merge request and put it in draft mode. I run:
glab mr create --fill-commit-body --yes --fill --source-branch "dev" --target-branch "staging" --draft --title "Staging Release"
I get the following error: remote: You are not allowed to push code to this project.
I check to make sure I'm logged in by running glab auth login --hostname $CI_SERVER_HOST --token $GITLAB_TOKEN
right before running the glab mr create
command.
I can run the exact same command locally using a terminal window with the exact same token. The token I use is a group access token with 'write repository' permissions.
These are the following things I tried and got the same error:
$GITLAB_HOST
and $GITLAB_TOKEN
env variables in the GitLab project I'm running the pipeline.glab mr create
command in a different project's pipelineWhen I run glab mr list --draft
in the same GitLab project's pipeline it works. I don't understand why GLab is saying the token I'm using doesn't have permissions when it actually does. Is there a GitLab project setting or GLab configuration setting I'm missing? I don't know what else to try to solve this error.
UPDATE: After doing some more research, I think the error has to do with GLab uses SSH when performing Git actions. Since creating a merge request in GitLab involves a git push, I think the error has to do with SSH. GLab doesn't provide any configuration for SSH.
I was not able to resolve my original error but as a workaround I used the glab api
command to create a merge request in a GitLab pipeline. This worked great with no issues.
This is the code that worked in a pipeline:
glab api --method "POST" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" projects/${CI_PROJECT_ID}/merge_requests \
--field title="Staging Release" \
--field description="This is a merge release description." \
--field source_branch="dev" \
--field target_branch="staging" \
--field reviewer_ids="12,2,48,63"