Search code examples
gitgithubtravis-ci

Travis CI is not updating git submodule


Travis CI is not updating the git submodule and it is throwing

ERROR: Permission to appdev/frontend.git denied to deploy key fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.

I have already created ssh-keygen and added as Deploy key in github, but still its giving permission denied

Submodule 'frontend' (git@github.com:appdev/frontend.git) registered for path 'frontend'
fatal: clone of 'git@github.com:appdev/frontend.git' into submodule path '/home/travis/build/appdev/b2b/frontend' failed
Failed to clone 'frontend'. Retry scheduled

The command "eval git submodule update --init --recursive " failed. Retrying, 2 of 3.

I have added the ssh key in Github Deploy Key

.travis.yaml

language: python

git:
  submodules: true
  quiet: true
  depth: false
...
...
.gitmodules

[submodule "frontend"]
    path = frontend
    url = git@github.com:appdev/frontend.git

Solution

  • If a submodule needs to reference a specific deploy key (key1), you need to change the submodule URL, using git submodule set-url -- /path/to/submodule key1:appdev/frontend.git

    With key1 an Host entry in your ~/.ssh/config, as commented:

    Host key1
      Hostname github.com
      User git
      IdentityFile ~/.ssh/key1
    

    With Travis-CI, that would be done in a before_script step.

    Note that Travis-CI recommends using User key instead.