gpt4 book ai didi

python - Gitlab-CI 使用 token 而不是 ssh key 从 setup.py 克隆私有(private)仓库?

转载 作者:行者123 更新时间:2023-12-05 07:04:42 25 4
gpt4 key购买 nike

我有一个 Python 项目,我想用 gitlab-ci 构建和测试它。

在我的 setup.py 文件中,我有一些目前可以使用 SSH key 下载的依赖项。

[setup.py]
...
install_requires=[
"test1 @ git+ssh://git@ssh.git.xxxx.de/path/to/repo/test1.git@1.1.0#egg=test1",
"test2 @ git+ssh://git@ssh.git.xxxx.de/path/to/repo/test2.git@1.0.2#egg=test2",
],

尽管有这种配置,我可以在 gitlab-ci 管道中使用“CI_JOB_TOKEN”来访问这些资源吗?

 echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc

或者我是否不可避免地必须在 gitlab-ci 中使用 ssh 私钥存储一个额外的 secret 变量,并为“before_script”中的每个阶段添加这个 key ?

[gitlab-ci.yml]
...
before_script:
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")

使用 ssh-keys 代替 https 有什么优势吗?

最佳答案

基于 GitLab CI/CD docs :

The Job environment variable CI_JOB_TOKEN can be used to authenticate any clones of dependent repositories.

如上所述,使用 CI_JOB_TOKEN 不会为管道提供对相关存储库的写访问权限。它只能用于克隆/下载依赖的存储库。

另一方面,使用 SSH 私钥 为您的管道提供更多权限。

还有其他方法可以访问依赖的存储库。您可以通过定义 Deploy Tokens 来访问您需要的存储库或 Deploy Keys为他们。

关于python - Gitlab-CI 使用 token 而不是 ssh key 从 setup.py 克隆私有(private)仓库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62889479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com