Access private Git submodules

You can access private Git submodules in Codemagic by saving the SSH key to your repository as an environment variable and referencing it in a custom post-clone script.

  1. Save the SSH key (e.g. SUBMODULE_SSH_KEY) for accessing the repository as an environment variable. Make sure to check Secure.

    SUBMODULE_SSH_KEY = -----BEGIN OPENSSH PRIVATE KEY-----
    ...
    -----END OPENSSH PRIVATE KEY-----
    
  2. Add the following post-clone script to enable fetching sources from private Git submodules.

       #!/usr/bin/env sh
    
       echo "${SUBMODULE_SSH_KEY}" > /tmp/submodule.key
       chmod 600 /tmp/submodule.key
       ssh-agent bash -c 'ssh-add "/tmp/submodule.key"; git submodule update --init --recursive'