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

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

问题描述

我正在从事一个内部项目,并希望在小组内部共享一个工具.

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 *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

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

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

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

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