无法从gitlab-ci.yml推送 [英] Cannot push from gitlab-ci.yml

查看:134
本文介绍了无法从gitlab-ci.yml推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与我的同事们一起,我们致力于一个C ++库,这一库每天变得越来越重要.我们已经通过gitlab-ci.yml文件构建了持续集成实用程序,该文件允许我们:

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 file that let us:

  • 建立并建立在调试模式下测试
  • 建立并建立在发布模式下测试
  • 使用Valgrind进行安全检查,例如内存泄漏,并检查我们的库中是否有任何我们不希望使用的清晰符号
  • 生成文档

所有使我们选择GitLab的东西!

All kind of stuff that made us choose GitLab !

我们想描述我们的整个图书馆,并在一个单独的项目中推广基准测试.我们已经使用 SSH密钥方法完成了类似的文档制作工作,但这次我们希望避免这种情况.

We would like to profile our whole library and push the benchmarks in a separate project. We have already done something like for out documentation using the SSH key method but we would like to avoid this this time.

我们尝试了如下脚本:

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
    - touch test.dat
    - 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://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.mycompany.home/developers/benchmarks.git HEAD:master
    - cd ..

我们还尝试了基本的git push origin master来推送更新的文件,但是每次我们得到相同的答案:

We also tried a basic git push origin master to push our updated files but each time we got the same answer:

remote: You are not allowed to upload code for this project.
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mycompany.home/developers/benchmarks.git/': The requested URL returned error: 403

两个项目都在同一个site下,我有权将两者都推入.我在哪里哪里做错了?

Both projects are under the same site and I have the rights to push in both. Where am I doing anything wrong here ?

推荐答案

gitlab ci令牌更像github.com中的deploy密钥,因此它仅具有对存储库的读取权限.要实际推送,您将需要生成一个个人访问令牌并使用它.

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.

最后,您的gitlab-ci.yml应该看起来像这样:

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 ..

这篇关于无法从gitlab-ci.yml推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆