是否可以使用私有 GitLab 存储库作为 GitLab CI 中的远程包含?如果是这样,如何?
Is it possible to use a private GitLab repo as a remote include in GitLab CI? If so, how?
鉴于我有一个包含此文件的私人仓库:
https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml
.my-snippet:
before_script:
- one command here...
- another thing here...
并且我想在另一个私人仓库的 .gitlab-ci.yml
文件中执行此操作:
https://gitlab.com/myuser/coderepo/-/raw/main/.gitlab-ci.yml
include:
remote: https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml
mycijob:
extends: .my-snippet
script:
- does a thing...
- probably does something else...
一个人怎么会去做这样的事情?我试了一下部署令牌,但在获取文件的原始内容时这似乎不起作用。我得到了 503。这有可能吗?
即使有更好、更简单的方法来处理这个问题也可以实现。
你可以对 gitlab 使用特殊的语法,只要它们在同一个实例上。您可以使用
这样的语法指定一个项目和可选的 ref 以及文件
include:
- project: 'myuser/snippets'
# optional ref, can point to a tag or branch, if not specified the default branch of the target repository is used
# ref: <git ref>
file:
- 'snippets.yml'
上的文档
鉴于我有一个包含此文件的私人仓库:
https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml
.my-snippet:
before_script:
- one command here...
- another thing here...
并且我想在另一个私人仓库的 .gitlab-ci.yml
文件中执行此操作:
https://gitlab.com/myuser/coderepo/-/raw/main/.gitlab-ci.yml
include:
remote: https://gitlab.com/myuser/snippets/-/raw/main/snippets.yml
mycijob:
extends: .my-snippet
script:
- does a thing...
- probably does something else...
一个人怎么会去做这样的事情?我试了一下部署令牌,但在获取文件的原始内容时这似乎不起作用。我得到了 503。这有可能吗?
即使有更好、更简单的方法来处理这个问题也可以实现。
你可以对 gitlab 使用特殊的语法,只要它们在同一个实例上。您可以使用
这样的语法指定一个项目和可选的 ref 以及文件
include:
- project: 'myuser/snippets'
# optional ref, can point to a tag or branch, if not specified the default branch of the target repository is used
# ref: <git ref>
file:
- 'snippets.yml'
上的文档