Using CI to update submodule

,

Using CI to update submodules

Hey everyone !

I’m splitting a monolithic repository into many, and I’m using git submodules to preserve the old CI in a main old repo.

My project look like this :

main_repo
├── sub_repo_1
├── sub_repo_2
└── sub_repo_3

I would like to run a pipeline on a schedule every night that updates each submodule to the latest current state of the master branch and then commit the change with a Gitlab user token.

Here is what I’m trying to do :

submodules:
  image: debian:latest
  only:
    - schedules
  script:
    - git submodule update --recursive --remote
    - git commit -a -m "update submodules"
    - git push "https://${GITLAB_USER_NAME}:${CI_GIT_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:$CI_COMMIT_REF_NAME"

But I only get an error during the git submodule :

252 $ git submodule update --recursive --remote
253 Host key verification failed.
254 fatal: Could not read from remote repository.
255 Please make sure you have the correct access rights
256 and the repository exists.
257 Unable to fetch in submodule path 'core-connector'
258
259 ERROR: Job failed: exit code 1

What am I doing wrong ?
Is it even possible to fetch the master branch of a submodule in Gitlab CI ?

Thanks for your attention and your time ! :grin:

Can you give more details like ‘rest of the pipeline’ 'Which executor you are running the job on` ?

It looks like your repository is setup with ssh keys and the priavate key to access gitlab is missing inside container.

Try adding the following to your .gitlab-ci.yml

variables:
  GIT_SUBMODULE_STRATEGY: normal