如何在带有 package.json 的 NPM 中使用 gitlab repo [英] how to use gitlab repo in NPM with package.json

查看:24
本文介绍了如何在带有 package.json 的 NPM 中使用 gitlab repo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个内部项目,想在小组内分享一个工具.

I'm working on a internal project and want to share a tools inside the group.

但如果我使用 npm 工具.它要么请求模块已在 npm 网站或公共 git repo 上注册.

but if I use the npm tools. it either request the module has registered on npm website or public git repo.

我正在使用 gitlab.并且有一个私人令牌.<代码>git+https://gitlab-ci-token:<private token>@<domain>/<username>/<repo_name>.git我试着把它放在 package.json 中但它不起作用.

I'm using gitlab. and there is a private token. git+https://gitlab-ci-token:<private token>@<domain>/<username>/<repo_name>.git i tried to put it like this in package.json but it's not working.

有没有办法通过授权安装私有 gitlab 存储库?

Is there a way to install a private gitlab repo with authorization?

非常感谢.

推荐答案

如果我正确理解您的问题,您希望运行 npm 的 CI 管道能够从您的 gitlab 中提取一个私有项目作为依赖项.

If I understand your question correctly, you want your CI pipeline which runs npm to be able to pull a private project from your gitlab as a dependency.

在这种情况下,您可以为此使用 gitlab 中的部署密钥机制(请参阅 这里).

In that case, you can use the deploy keys mechanism in gitlab for that (see here).

首先生成一个 SSH 密钥对.您可以为此使用 ssh-keygen -t rsa.

First generate a SSH key pair. You can use ssh-keygen -t rsa for that.

然后进入私有仓库的 gitlab 页面,找到 Deploy Keys 设置.您应该在那里粘贴您刚刚生成的公钥.

Then go to the private repository's gitlab page and locate the Deploy Keys setting. There you should paste the public key you just generated.

然后转到在其 CI 中运行 npm 的项目并找到 Variables 页面.例如,创建一个名为 SSH_PRIVATE_KEY 的新私有变量,然后将您生成的私有密钥粘贴到那里.

Then go to the project that runs npm in its CI and locate the Variables page. Create a new private variable with the name SSH_PRIVATE_KEY for instance and paste the private key you generated there.

最后,在您的 .gitlab-ci.yml 文件中添加以下内容,以便您的私钥可用于您的 CI 环境:

Finally, in your .gitlab-ci.yml file add the following so that your private key will be available to your CI environment:

- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *
	StrictHostKeyChecking no

" > ~/.ssh/config'

现在应该设置您的 CI 环境,以便可以提取您的私有存储库.

Your CI environment should now be setup so that in can pull your private repository.

这篇关于如何在带有 package.json 的 NPM 中使用 gitlab repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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