Search code examples
gitazure-devopsazure-pipelinesgit-submodules

How to I checkout with recursive submodules in Azure DevOps in the same project but different repo without disabling protections?


Different from these which are accessing a different project

Different from these which use github:

Different from this as it is for accessing another project, not the same project.

Anyway mine is a simple enough layout I have a project with the following git repos

  • my-repo (has submodules my-app, my-service-a, my-service-b)
  • my-app
  • my-service-a (has submodules my-lib)
  • my-service-b (has submodules my-lib)
  • my-lib

The .gitmodules uses relative paths as required by the Submodules documentation that is in my-repo .gitmodules looks like

[submodule "my-app"]
    path = my-app
    url = ../my-app
[submodule "my-service-a"]
    path = my-service-a
    url = ../my-service-a
[submodule "my-service-b"]
    path = my-service-b
    url = ../my-service-b

I also tried full URLs with no luck.

The checkout step looks like this

steps:
  - checkout: self
    submodules: recursive
    persistCredentials: true

But in the end I get the following

Cloning into '/home/vsts/work/1/s/my-app'... remote: TF401019: The Git repository with name or identifier my-app does not exist or you do not have permissions for the operation you are attempting. fatal: repository 'https://dev.azure.com/XXXXXXXXXXXXXXXXXX/_git/my-app/' not found

Technically the answer https://stackoverflow.com/a/79179735/242042 and TF401019: The Git repository with name or identifier abc does not exist or you do not have permissions for the operation you are attempting would work, but it does them by bypassing the protections.


Solution

  • I can clone the submodules successfully with the same layout and checkout step with yours, no matter I use the full URL or the URL like url = ../my-app

    repo

    Test result:

    log

    To access the repo in the same project, please double check if the option Protect access to repositories in YAML pipelines is off. Protect access to repositories in YAML pipelines

    If you still cannot checkout the submodules, please check if the pipeline build service accounts account have the Read access of the repo. Please refer the detailed step here.