通过 CI runner 将文件推送到 gitlab-ci [英] Push files to gitlab-ci via CI runner

查看:21
本文介绍了通过 CI runner 将文件推送到 gitlab-ci的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 gitlab CI runner 来测试我的代码并生成一些文件.我只想通过 CI runner 将生成的文件推送到 gitlab 存储库.有什么办法吗?

I am using gitlab CI runner to test my code and generating some files. I just want to push the generated files to gitlab repository via CI runner. Is there any way to do that ?

推荐答案

我已经解决了这个问题:

I have resolved this issue by doing this:

注意:如果你想 git push 到一个非受保护的分支,不要将 runner 变量设置为受保护

Note: If you want to git push to a non protected branch do not set the runner variable as protected

  1. 使用 api 范围生成新的 gitlab 访问令牌:用户设置>访问令牌
  2. 使用新令牌将受保护的 CI 变量添加到您的项目设置中:您的项目 >设置 >秘密变量使用变量名CI_PUSH_TOKEN
  3. 使用变量名CI_USERNAME
  4. 使用您的用户名添加另一个受保护的 CI 变量
  1. Generate new gitlab access token with api scope: User Settings > Access Tokens
  2. Add a protected CI variable into your project settings with the new token: Your project > Settings > Secret variable using variable name CI_PUSH_TOKEN
  3. Add another protected CI variable with your username using variable name CI_USERNAME

然后您可以在 gitlab-ci 脚本中使用此令牌而不是默认令牌.例如:

Then you can use this token instead of the default in you gitlab-ci script. for example:

before_script:
  - git remote set-url origin https://${CI_USERNAME}:${CI_PUSH_TOKEN}@gitlab.com/${CI_PROJECT_NAME}.git
  - git config --global user.email '${GITLAB_USER_EMAIL}'
  - git config --global user.name '${GITLAB_USER_ID}'

...

- git checkout -B branch
- # do the file changes here
- git commit -m '[skip ci] commit from CI runner'
- git push --follow-tags origin branch

这篇关于通过 CI runner 将文件推送到 gitlab-ci的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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