There are several earlier posts that reference this same error. For me, this is happening in a pipeline. And while I want to solve the error, I’m more interested in the proper way to automate working with the repo in the pipeline.
If I’m reading the docs correctly, a $CI_JOB_TOKEN and credentials are auto-generated for each job allowing interaction with the repo.
Here is the script section of my job code:
script:
# Checkout the latest version of the main branch
- git checkout main
- git pull
# Create a new branch for the user
- git checkout -b ${NEW_MEMBER_USER_NAME}
# Create a new folder for the new client
- mkdir -p clients/${NEW_MEMBER_USER_NAME}
# Copy client files into the new folder
- cp -R files/default/* clients/${NEW_MEMBER_USER_NAME}
# Commit changes to the new branch
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git add .
- git commit -m "Add new client files for ${NEW_MEMBER_USER_NAME}"
- git push --set-upstream origin ${NEW_MEMBER_USER_NAME}
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
when: always
The error happens on git push “Remote: You are not allowed to upload code. 403”
My next step was going to either use the $CI_JOB_TOKEN or create a dedicated token, add access it from the CI/CD Variables, but other posts imply that fails too.
Also, instead using raw git commands, I thought about installing gitlab cli and using it since I also need to create a related issue and merge request (later.)
Ultimately though, this feels like the wrong direction. Am I on the right track, or is there a better, “best practices” way to manipulate a repo, branches, merge requests, etc, in a pipeline?
The repo is private. I’m the owner / maintainer / only user.