如何以编程方式在GitLab CI中获取和使用gitlab-ci-token?

时间:2018-07-24 09:02:14

标签: python continuous-integration gitlab gitlab-ci continuous-deployment

诚然,我知道如何使用它,但是在设置它时遇到了问题。到目前为止,我已经建立了一个新的个人访问令牌(出于这个问题的目的,我将其定义为ABCDEFGHIJKLMNOPQRSTUZWXYZ0,在那里我将提供24小时的完全访问权限和功能。假设我的用户名是ABC.123,电子邮件是abc123@foobar.com,我已尝试创建一个作业,在该作业中,只要满足某些条件,便会将新更新推送到GitLab存储库。我尝试过各种不同的方法,我在网上遇到过,即:

>>> git push

返回了

fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use
    git push origin HEAD:<name-of-remote-branch>`.

接下来,我尝试了:

>>> git push origin HEAD:master --force

返回:

remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mycompany.com/path/repository.git/': The requested URL returned error: 403

然后,我尝试了:

>>> git push https://gitlab-ci-token:ABCDEFGHIJKLMNOPQRSTUZWXYZ0@gitlab.mycompany.com:path/repository.git HEAD:master

返回:

remote: The project you were looking for could not be found.
fatal: repository 'https://gitlab-ci-token:ABCDEFGHIJKLMNOPQRSTUZWXYZ0@gitlab.mycompany.com:path/repository.git/' not found

在其他示例之后,我尝试:

>>> git push https://ABC.123:ABCDEFGHIJKLMNOPQRSTUZWXYZ0@gitlab.mycompany.com:path/repository.git HEAD:master

的输出是:

remote: The project you were looking for could not be found.
fatal: repository 'https://ABC.123:ABCDEFGHIJKLMNOPQRSTUZWXYZ0@gitlab.mycompany.com:path/repository.git/' not found

最后,我尝试在其中添加origin

>>> git push origin https://gitlab-ci-token:ABCDEFGHIJKLMNOPQRSTUZWXYZ0.mycompany.com:path/repository.git HEAD:master

这给了:

error: src refspec https://gitlab-ci-token:ABCDEFGHIJKLMNOPQRSTUZWXYZ0@gitlab.mycompany.com does not match any.
error: failed to push some refs to 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mycompany.com/path/repository.git'

还有更多,但我似乎找不到可行的解决方案。我有90%的人可能只是在格式化错误的格式,或者我实际上没有gitlab-ci令牌(而且它与个人访问令牌不同),但是我还是很想把这个想出来(解决;计算出;弄明白。一位消息人士还说,目前尚不可能,因为我发现很多其他公司都设法使其正常运行。对于在哪里找到gitlab-ci令牌以及如何正确格式化推送以使我能够获得所需的结果,我将不胜感激。

我的gitlab-ci.yml文件具有以下内容:

update:
  script:
    - git config user.email "abc123@foobar.com"
    - git config user.name "ABC.123"
    - git config --global push.default simple
    - python runUpdate.py

我的runUpdate.py文件具有以下内容:

def update():
    doSomething(); # Some random function
    os.system('git add -A');
    os.system('git commit -m "Automated Repo Update"');
    os.system('git push'); # issue triggered here...

update();

0 个答案:

没有答案