小编Chl*_*ett的帖子

您如何使用gitlab-ci作业推送到gitlab存储库?

我是GitLab CI / CD作业的新手,但是我试图建立一个Python脚本,当将其推送到GitLab时,它会触发CI / CD作业运行它,并调用一个内部函数来再次推送到GitLab,前提是一定要符合条件。因此,例如,假设我有以下内容:

def hasFileInDirectory():
    # checks if the current directory has at least 1 other file in it
    if (1 or more files exist):
        print 'Great! You have enough files!';
    else:
        print 'Oh no! You need more files! Let me create one!';
        createFile('missingFile'+str(random.randint(0,1000000)+'.txt');
        os.system('git add -A');
        os.system('git commit -m "Automatically added new file..."');
        os.system('git push origin HEAD:master --force');
Run Code Online (Sandbox Code Playgroud)

如果我自己从命令行运行此函数,则该函数似乎运行得很好,但是,它似乎无法在GitLab CI / CD作业中运行。我得到的输出是:

remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:xxxxx@gitlab.com/path_to/my_repository.git/': The …
Run Code Online (Sandbox Code Playgroud)

git python-2.7 gitlab gitlab-ci gitlab-ci-runner

8
推荐指数
1
解决办法
4192
查看次数

如何解决“远程:您不允许上载代码”。GitLab CI / CD作业出错?

我目前正在尝试使用GitLab运行CI / CD作业,该作业运行一个Python文件,该文件对特定的存储库进行更改,然后提交并将这些更改推送到master。在存储库中,我还担任过Master的角色。看来,所有git功能运行正常除外git push,这导致fatal: You are not currently on a branch.与使用git push origin HEAD:master --force,这导致fatal: unable to access 'https://gitlab-ci-token:xxx@xxx/project.git/': The requested URL returned error: 403。我一直在寻找在线解决方案,一个是这个,另一个是不保护它,而我现在还找不到。这也是GitLab存储库中的一个子项目。

现在,这几乎就是我的.gitlab-ci.yml模样。

before_script:
  - apt-get update -y
  - apt-get install git -y
  - apt-get install python -y
  - apt-get python-pip -y

main:
  script:
    - git config --global user.email "xxx@xxx"
    - git config --global user.name "xxx xxx"
    - git config --global …
Run Code Online (Sandbox Code Playgroud)

python linux gitlab gitlab-ci gitlab-ci-runner

6
推荐指数
3
解决办法
2577
查看次数

标签 统计

gitlab ×2

gitlab-ci ×2

gitlab-ci-runner ×2

git ×1

linux ×1

python ×1

python-2.7 ×1