![](/img/trans.png)
[英]Build error in gitlab CI server (maybe related to git submodules)
[英]Stopping GitLab from skipping Git submodules during CI job?
我正在測試在 GitLab 頁面上部署 Hexo 站點。 我目前正在使用某人發布到 GitHub 的主題,因此在我的 Hexo 項目的themes
文件夾中有一個 Git 子模塊,因此頂級.gitmodules
文件如下所示:
[submodule "themes/Hacker"]
path = themes/Hacker
url = https://github.com/CodeDaraW/Hacker.git
我正在使用 Hexo doc 推薦的 YAML 文件(針對當前節點更新)進行 CI 設置,並且 CI 作業似乎進行得很順利,只是它隨機決定跳過 Git 子模塊設置:
Getting source from Git repository 00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/jjeffrey/jjeffrey.gitlab.io/.git/
Created fresh repository.
Checking out 76f8757a as master...
Skipping Git submodules setup
Restoring cache 00:01
Checking cache for default...
FATAL: file does not exist
這會阻止站點正確生成 HTML/CSS 文件,因為沒有主題存在:
$ hexo generate
INFO Validating config
INFO Start processing
INFO Files loaded in 100 ms
WARN No layout: 1970/01/01/hello-world/index.html
WARN No layout: 1970/01/01/test_new/index.html
WARN No layout: archives/index.html
WARN No layout: archives/1970/index.html
WARN No layout: archives/1970/01/index.html
WARN No layout: index.html
INFO Generated: archives/index.html
INFO Generated: archives/1970/index.html
INFO Generated: archives/1970/01/index.html
INFO Generated: index.html
INFO Generated: 1970/01/01/hello-world/index.html
INFO Generated: 1970/01/01/test_new/index.html
INFO 6 files generated in 13 ms
如何確保 GitLab 實際正確加載 Git 子模塊以便我的主題加載?
我通過在.gitlab-ci.yml
添加一行來更新 Git 子模塊來解決我的問題,然后再繼續執行腳本的其余部分。
image: node:14.17.1
cache:
paths:
- node_modules/
before_script:
- git submodule update --init
- npm install hexo-cli -g
- npm install
pages:
script:
- hexo generate
artifacts:
paths:
- public
only:
- master
來自gitlab 文檔 Using Git submodules with GitLab CI/CD :
在 CI/CD 作業中使用 Git 子模塊
要使子模塊在 CI/CD 作業中正常工作:
確保對位於同一 GitLab 服務器中的子模塊使用相對 URL。
您可以將 GIT_SUBMODULE_STRATEGY 變量設置為 normal 或 recursive 以告訴運行程序在作業之前獲取您的子模塊:
variables: GIT_SUBMODULE_STRATEGY: recursive
另請參閱https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-submodule-strategy 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.