通过 CI runner 将文件推送到 gitlab

编程入门 行业动态 更新时间:2024-10-11 11:19:54
本文介绍了通过 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

  • 使用 api 范围生成新的 gitlab 访问令牌:用户设置>访问令牌
  • 使用新令牌将受保护的 CI 变量添加到您的项目设置中:您的项目 >设置 >秘密变量使用变量名CI_PUSH_TOKEN
  • 使用变量名CI_USERNAME
  • 使用您的用户名添加另一个受保护的 CI 变量
  • Generate new gitlab access token with api scope: User Settings > Access Tokens
  • Add a protected CI variable into your project settings with the new token: Your project > Settings > Secret variable using variable name CI_PUSH_TOKEN
  • 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 ${CI_USERNAME}:${CI_PUSH_TOKEN}@gitlab/${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

    本文发布于:2023-11-15 22:22:40,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1598476.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   CI   runner   gitlab

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!