Cannot push from gitlab-ci.yml

后端 未结 3 1566
礼貌的吻别
礼貌的吻别 2020-12-23 12:18

With my colleagues, we work on a C++ library that becomes more and more important each day. We already built continuous integration utilities through the gitlab-ci.yml

3条回答
  •  自闭症患者
    2020-12-23 12:35

    The gitlab ci token is more like the deploy key in github.com, so it only has read access to the repository. To actually push you will need to generate a personal access token and use that instead.

    First you need to generate the token as shown here in the gitlab documentation. Make sure you check both the read user and api scopes. Also this only works in GitLab 8.15 and above. If you are using an older version and do not wish to upgrade there's an alternative method I could show you but it is more complex and less secure.

    In the end your gitlab-ci.yml should look something like this:

    test_ci_push:
      tags:
        - linux
        - shell
        - light
      stage: profiling
      allow_failure: false
      only:
        - new-benchmark-stage
      script:
        - git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git &> /dev/null
        - cd benchmarks
        - echo "This is a test" > test.dat
        - git config --global user.name "${GITLAB_USER_NAME}"
        - git config --global user.email "${GITLAB_USER_EMAIL}"
        - git add --all
        - git commit -m "GitLab Runner Push"
        - git push http://${YOUR_USERNAME}:${PERSONAL_ACCESS_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git HEAD:master
        - cd ..
    

提交回复
热议问题