Make commit in (shared) CI runner and push to repository

Hi,

my goal is to run a scheduled pipeline and push sth. to my repository. So, I want to run some commands or scripts that may makes some modifications in the pipeline. And then run another script to check if there were any modifications made and if so then make a commit and push this to a new branch to my repository.

However pushing to my repository failed because whether using ssh or https the authentication is denied.

remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:[MASKED]@gitlab.com/thacoon/example.git/': The requested URL returned error: 403

or (the token is protected/not visible here)

remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://thacoon:@gitlab.com/thacoon/example.git/'

I already have read some issues which similar problems. But they all have hosted a GitLab instance on there own, which I am not I am using https://gitlab.com and the shared runners.

Is it possible to push to my repository using the shared runners? And if yes do you see if I have make a mistake?

My .gitlab-ci.yml looks sth like this.

doSth:
      image: image

      script:
        - chmod 700 doSth.sh
        - chmod 700 autoUpgrade.sh
        - ./doSth.sh
        - ./autoUpgrade.sh

My autoUpgrade.sh looks sth. like this.

#!/bin/bash

if [[ `git status --porcelain` ]]; then
    git config --global user.email "email@example.com"
    git config --global user.name "example"
    export BRANCH_NAME=change-sth-`date +"%s"`
    git checkout -b ${BRANCH_NAME}
    git add -u
    git commit -m 'change sth.'
    # I tried using ssh and https
    # chmod 0400 $CI_DEPLOY_KEY
    # GIT_SSH_COMMAND="ssh -i ${CI_USER_TOKEN}" git push --set-upstream origin ${BRANCH_NAME}
    git push https://${CI_USER}:${CI_USER_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git ${BRANCH_NAME}
else
  echo "Nothing changed"
fi