问题描述
我是不熟悉GitLab CI/CD作业的人,但是我试图建立一个Python脚本,当将其推送到GitLab时,它会触发CI/CD作业来运行它,并调用一个内部函数来再次推送到GitLab只要满足某些条件.因此,例如,假设我有以下内容:
I am new to GitLab CI/CD jobs, but I'm trying to set up a Python script that when pushed to GitLab, triggers the CI/CD job to run it, and call an internal function that pushes to GitLab again provided that certain criteria are met. So, for example, suppose I have the following:
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');
如果我自己从命令行运行此函数,则该函数似乎运行得很好,但是,它似乎无法在GitLab CI/CD作业中运行.我得到的输出是:
This function seems to run perfectly fine if I run it myself from the command line, however, it seems to not be able to run in the GitLab CI/CD job. The output I am getting is:
remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:[email protected]/path_to/my_repository.git/': The requested URL returned error: 403
当我致电git push
时会发生此错误,所以我想知道如何解决此问题.我将非常感谢您的帮助!
This error occurs when I call git push
so I was wondering what I could do to fix this. I would really appreciate any help!
推荐答案
GitLab CI运行程序还不能推送回购协议:存在一个此处的提案正在进行中.
A GitLab CI runner cannot yet push to a repo: there is a proposal in progress here.
同时,您可以使用SSH URL ,并使用:
In the meantime, you can use an SSH URL, with:
- 通过GitLab中的设置">"CI/CD管道" Web界面,将SSH私钥定义为秘密变量,
- SSH密钥的公共部分存储为同一Web UI的部署密钥设置">存储库">部署密钥"部分.
或者,如此处提到的 /a>,则可以在个人资料的设置"中使用个人访问令牌".
Or, as mentioned here, you can use a "personal access token" in Settings of your profile.
使用gitlab-ci.yml
With a gitlab-ci.yml
script:
- url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*@//g"`
- git remote set-url origin "https://gitlab-ci-token:${CI_TAG_UPLOAD_TOKEN}@${url_host}"
CI_TAG_UPLOAD_TOKEN
是Secret变量
这篇关于您如何使用gitlab-ci作业推送到gitlab存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!