如何在 gitlab runner 中使用个人 github 访问令牌

How to use personal github access token with gitlab runner

mirrored a private repository from Github 到 运行 使用 gitlab 运行 构建。我的项目在 Github 上托管了私有 gem,构建失败

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 to mirror private repositories from Github to 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

?

我设法通过将 BUNDLE_GITHUB__COM 添加到 .gitlab-ci.yml 来做到这一点,现在将其提交到源代码:

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