How do I use submodules with Azure DevOps when the submodules are in Gitlab?

  • Page Owner: Not Set
  • Last Reviewed: 2020-05-07

I have a project that uses submodules. The main repo is in Gitlab, but is mirrored to DevOps for deployment. The submodule is also in Gitlab, but is not mirrored. How do I get DevOps to be able to pull the submodule?


Answer

You can use the Jenkins (Win) deployment key in gitlab, and a command on DevOps to accomplish this.

First: Enable the Jenkins (Win) deployment key in your project in Gitlab. This is under Settings -> Repository -> Deploy Keys

Next: Add the Jenkins private key to your project in DevOps. This is under Pipelines -> Library -> Secure Files. Upload the private key as a file there. (The key is the Developer Passwords 1Pass vault)

Next: Add these as your first steps in your pipeline (YAML is included here, but you can also use the same steps in non-YAML builds):

- task: InstallSSHKey@0
  inputs:
    knownHostsEntry: 'gitlab.blendinteractive.com,54.200.29.232 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCaeX0QacYeFkPjyLM5bBaUk3z/bpxzloPVic1PJ6/bH6fzhak6DykIqE6qmx8uuLY2/k7Ct0lcnrhYGayx0gWE='
    sshPublicKey: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1/cGQff6evKgWePpSZX7ZTUGtXD7r9DiDm0hkzySvDI6E+oLFr8cIi3dm8AwoLvP2787CT1X9kxyRztgV11MFQvYm79DAt/y2QVevrp9FYGnUxbWdmxDnPV7CsRQwdwUx6o0Ewy/MDc4eTfwcMWWwu6MOVcTapxJRhF/7RYVYU9TbSM3GX4lbcVOnG45qBenPUpWvBYpQ9GcgSYLwZR2ms5uHVSJypPDKJDLgMleYUoU3YBcfETzagrZfL5McWMi099Cd0+stVBN1GTrYhsq+Ikms0116emk7Nub/SxULvFBsg37pyddBo/9ChJbKDyshC4TcwDMAe6IRgaxN2kmR'
    sshKeySecureFile: 'id_rsa'

- task: CmdLine@2
  inputs:
    script: 'git submodule update --init'
    workingDirectory: '$(Build.SourcesDirectory)'

Note: you may need to change id_rsa to whatever you named the private key in the pipline Secure Files library.

Also note: the first time you run the job, it will pause and ask for permission to access the file. Click on the progress icon so you can grant it permission.