GitLab CI: How to properly push file to a repo using ci file?

0

I’m trying to setup a GitLab CI pipeline which runs a script (convert-inventory-format.sh) that update a yaml file. I would then like to commit that file to a Git repository and push it.

However, the pipeline fails with the error:

remote: You are not allowed to upload code.

The user provided works when trying this process outside of a CI pipeline

this is my gitlab-ci file:

stages:
  - update_yaml

update_yaml:
  tags:
    - git
  stage: update_yaml
  script:
    - chmod +x $CI_PROJECT_DIR/convert-inventory-format.sh
    - $CI_PROJECT_DIR/convert-inventory-format.sh
    - ls
    - echo "Deploying to Git repository"
    - git config user.email "xxx"
    - git config user.name "xxx"
    - git add $CI_PROJECT_DIR/wiki_inventory.yaml
    - git status
    - git commit -m "Update formatted YAML"
    - git push origin InventoriesWiki
  variables:
    GIT_STRATEGY: fetch
    GIT_CHECKOUT: "false"
    GIT_PUSH_OPTS: "--force"
    GIT_USER: XXX
    GIT_PASSWORD: xxx

i’m not sure why this pipeline fails, what is the best practice for running git commits in a gitlab ci pipeline?

I appericiate your help

GitLab CI jobs do not have permission to push to repositories. You need to create Token with write repository permission and use that to authenticate to GitLab when pushing back to repository from a CI Job.