如何在gitlab运行程序中使用个人github访问令牌

时间:2018-12-18 14:30:03

标签: gitlab-ci gitlab-ci-runner

mirrored a private repository from Github使用gitlabRunner运行构建。我的项目在Github上托管了私人宝石,并且构建失败

Fetching git@github.com:private/gem.git
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Retrying `git clone 'git@github.com:private/gem.git' "/builds-ci/gitlab/repo/vendor/ruby/2.4.0/cache/bundler/git/gem-a356dd016736a58b8b77677e8d7df689f8f43ada" --bare --no-hardlinks --quiet` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git@github.com:private/gem.git' "/builds/gitlab-ci/repo/vendor/ruby/2.4.0/cache/bundler/git/gem-a356dd016736a58b8b77677e8d7df689f8f43ada" --bare --no-hardlinks --quiet` in directory /builds/gitlab-ci/repo has failed.Host key verification failed.
fatal: Could not read from remote repository.

我使用personal Github access token将私有存储库从Github镜像到Gitlab。 There is a way使用Github访问令牌通过捆绑程序克隆私有gem,而无需设置SSH密钥:

export BUNDLE_GITHUB__COM=x-access-token:<token>

我是否需要创建一个单独的访问令牌并将其粘贴到.gitlab-ci.yml

image: ruby:2.4.1

variables:
  BUNDLE_GITHUB__COM=x-access-token:<token>

...

或者我可以使用用于镜像来自Github的存储库的令牌?像这样

variables:
  BUNDLE_GITHUB__COM=x-access-token:$SOME_GITLAB_JOB_ACCESS_TOKEN

1 个答案:

答案 0 :(得分:0)

我设法通过向BUNDLE_GITHUB__COM添加.gitlab-ci.yml到现在将其提交到源代码中来实现这一目标:

# .gitlab-ci.yml
variables:
  BUNDLE_GITHUB__COM=x-access-token:<token>
...