Как использовать субмодуль в моем Gitlab Runner? - PullRequest
0 голосов
/ 02 ноября 2019

Вкл. https://gitlab.com

  1. Я создал частную группу под названием test-kirby-group.
  2. Я создал частный проект в этой группе под названием test-project-1
  3. Я создал еще один частный проект в этой группе под названием test-sub-project
  4. Я создал оба новых проекта с помощью readme по умолчанию.
  5. В test-kirby-group /test-project-1, я добавил файл .gitmodules
[submodule "vendor/submodules/test-sub-project"]
    path = submodules/test-sub-project
    url = ../../test-group-kirby/test-sub-project.git
В test-kirby-group / test-project-1 я добавил файл .gitlab-ci.yml
variables:
    GIT_SUBMODULE_STRATEGY: recursive

before_script:
    - apk update && apk add git
    - git submodule sync --recursive
    - git submodule update --init --recursive

test:
    script:
        - pwd
        - ls -al
        - ls -al ../
        - ls -al ../../

... Затем я проверил вывод задания ...

Running with gitlab-runner 12.3.0 (a8a019e0)
  on docker-auto-scale ed2dce3a
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:e216e233b2581d7f45d2bc2c4dce4f1f293267b29c45bfd929d038a9a67b4058 for ruby:2.5 ...
Running on runner-ed2dce3a-project-15133453-concurrent-0 via runner-ed2dce3a-srm-1572642947-b5456b44...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/test-group-kirby/test-project-1/.git/
Created fresh repository.
From https://gitlab.com/test-group-kirby/test-project-1
 * [new ref]         refs/pipelines/93160262 -> refs/pipelines/93160262
 * [new branch]      master                  -> origin/master
Checking out b624748a as master...

Updating/initializing submodules recursively...
$ apk update && apk add git
/bin/bash: line 89: apk: command not found
$ git submodule sync --recursive
$ git submodule update --init --recursive
$ pwd
/builds/test-group-kirby/test-project-1
$ ls -al
total 48
drwxrwxrwx. 3 root root 4096 Nov  1 21:17 .
drwxrwxrwx. 4 root root 4096 Nov  1 21:17 ..
drwxrwxrwx. 6 root root 4096 Nov  1 21:17 .git
-rw-rw-rw-. 1 root root  274 Nov  1 21:17 .gitlab-ci.yml
-rw-rw-rw-. 1 root root  141 Nov  1 21:17 .gitmodules
-rw-rw-rw-. 1 root root   18 Nov  1 21:17 README.md
$ ls -al ../
total 32
drwxrwxrwx. 4 root root 4096 Nov  1 21:17 .
drwxrwxrwx. 3 root root 4096 Nov  1 21:17 ..
drwxrwxrwx. 3 root root 4096 Nov  1 21:17 test-project-1
drwxrwxrwx. 3 root root 4096 Nov  1 21:17 test-project-1.tmp
$ ls -al ../../
total 24
drwxrwxrwx. 3 root root 4096 Nov  1 21:17 .
drwxr-xr-x. 1 root root 4096 Nov  1 21:17 ..
drwxrwxrwx. 4 root root 4096 Nov  1 21:17 test-group-kirby
Job succeeded

Вопрос: 1. Стоит ли ожидать каталог с названием vendor? 2. Если так, то почему он не клонировал?

1 Ответ

1 голос
/ 06 ноября 2019

Возможно, вы неправильно добавили git submodule.

В test-kirby-group/test-project-1 выполните следующее:

  • Удалите текущий .gitmodules, созданный вручную.
  • Выполнить git submodule add <git@gitlab ...> <path/to/submodule>
  • Теперь вам может понадобиться отредактировать сгенерированную .gitmodules из вышеприведенной команды, чтобы использовать относительный URL-адрес (то есть то, что у вас уже есть url = ../../test-group-kirby/test-sub-project.git), чтобы он могработа с GitLab CI
  • Вам не нужен ваш текущий before_script, пока вы используете gitlab-runner v1.10 +, вам нужно только следующее в вашем скрипте CI:
variables:
    GIT_SUBMODULE_STRATEGY: recursive

См. Использование субмодулей Git с GitLab CI для получения дополнительной информации.

...