如何使用个人访问令牌从CircleCI构建推送到Github [英] How to push a commit to Github from a CircleCI build using a personal access token
问题描述
giantswarm / docs-content
执行构建时,我想将一个提交推送到另一个仓库 giantswarm / docs
。 我在的
部署
部分有 circle.yml
:
git config credential.helper cache
git config user。电子邮件<一些经过验证的电子邮件>
git config user.nameGithub Bot
git clone --depth 1 https:// $ {GITHUB_PERSONAL_TOKEN}:x-oauth-basic@github.com/giantswarm/docs.git
cd docs /
git commit --allow-empty -m通过docs-content触发构建和发布
git push -u原点大师
这失败
a>在这个错误消息的最后一个命令中: 错误:您正在使用身份验证的密钥已被标记为只读。
致命:无法从远程存储库读取。
GITHUB_PERSONAL_TOKEN
环境变量设置为用户的个人访问令牌(已使用 repo
范围创建)访问私人回购 giantswarm / docs
。另外,我将该用户添加到具有该回购的管理权限的团队。
当我在新的Ubuntu VM中执行该命令时,该系列命令正常工作。任何想法为什么它不在CircleCI?
感谢 Ali Amin 我现在有这个工作解决方案:
版本:2
工作:
构建:
机器:true
步骤:
- 运行:
名称:克隆文档
working_directory:〜/ workdir
命令:|
git clone --depth 1 https:// $ {DOCS_GITHUB_TOKEN} @ github.com / giantswarm / docs.git
- deploy:
名称:触发器文档部署
working_directory: 〜/ workdir / docs
命令:|
git config credential.helper'cache --timeout = 120'
git config user.email< email>
git config user.nameDeployment Bot
git commit --allow-empty -m触发器部署
#悄悄推送以防止在日志中显示令牌
git push -q https:// $ {DOCS_GITHUB_TOKEN} @ github.com / giantswarm / docs.git master
一些注意事项:
- 首先
git clone
。 - 所有后续的
git
命令必须在克隆目录中执行。working_directory
简化了这一点。
- 标记
DOCS_GITHUB_TOKEN
是一个< href =https://github.com/settings/tokens =nofollow noreferrer> personal access token withrepo
目标存储库的作用域。
When executing a build for git repository giantswarm/docs-content
in CircleCI, I'd like to push a commit to another repository giantswarm/docs
.
I have this in the deployment
section of circle.yml
:
git config credential.helper cache
git config user.email "<some verified email>"
git config user.name "Github Bot"
git clone --depth 1 https://${GITHUB_PERSONAL_TOKEN}:x-oauth-basic@github.com/giantswarm/docs.git
cd docs/
git commit --allow-empty -m "Trigger build and publishing via docs-content"
git push -u origin master
This fails in the very last command with this error message:
ERROR: The key you are authenticating with has been marked as read only.
fatal: Could not read from remote repository.
The GITHUB_PERSONAL_TOKEN
environment variable is set to a user's personal access token, which has been created with repo
scope to access the private repo giantswarm/docs
. In addition, I added the user to a team that has admin permissions for that repo.
That series of commands works just fine when I execute it in a fresh Ubuntu VM. Any idea why it doesn't on CircleCI?
Thanks to the hint by Ali Amin I now have this working solution:
version: 2
jobs:
build:
machine: true
steps:
- run:
name: Clone docs
working_directory: ~/workdir
command: |
git clone --depth 1 https://${DOCS_GITHUB_TOKEN}@github.com/giantswarm/docs.git
- deploy:
name: Trigger docs deployment
working_directory: ~/workdir/docs
command: |
git config credential.helper 'cache --timeout=120'
git config user.email "<email>"
git config user.name "Deployment Bot"
git commit --allow-empty -m "Trigger deployment"
# Push quietly to prevent showing the token in log
git push -q https://${DOCS_GITHUB_TOKEN}@github.com/giantswarm/docs.git master
Some notes:
- The
git clone
is first. - All subsequent
git
commands have to be executed in the clone directory.working_directory
simplifies this a great deal. - The token
DOCS_GITHUB_TOKEN
is a personal access token withrepo
scope for the target repository.
这篇关于如何使用个人访问令牌从CircleCI构建推送到Github的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!