Search code examples
azure-devopsazure-devops-self-hosted-agent

Azure Devops pipelines - submodules not get updated by default


In Azure devops pipelines submodules are not getting updated by default.

To reproduce the problem.

Source Code

https://github.com/forvaidya/submodule.git
https://github.com/forvaidya/supermodule.git

Updates doesn't happen unless I have following step in pipeline. I Expect this to happen by default or some global variable to enable / disable it and default should be true (Refresh submodules)

- script: |
      git submodule deinit --all
      git submodule init
      git submodule update --remote
  displayName: 'Refresh Submodule'

In Private Git repository above steps will not work and will get HTTP errors

Azure Logs in Gist


Solution

  • You can try checking the option Checkout submodules for your pipeline. See below steps:

    Click 3dots --> Triggers on your yaml pipeline edit page.

    enter image description here

    Go to Yaml tab-->Get sources--> checking Checkout submodules

    enter image description here

    Then the Azure devops pipelines will automatically update the submodule when you run your pipeline.

    If above step fails to update the submodule due to the reason that submodule repo is private or in a different organization and cannot be accessed from your azure devop pipeline. You can try configuring the submodule credential like below.

    1, Set a pipeline secret variable to hold the credential (eg.PAT) for the submodule repo.

    enter image description here

    2, Then add git config submodule.SubmoduleRepo.url to above your git command in the script task to update the submodule.

    - script: |
          git submodule deinit --all
          git submodule init
          git config submodule.TestRepo.url https://$(PAT)@dev.azure.com/TestOrganization/TestProject/_git/TestRepo
          git submodule update --remote
        enabled: true
    

    See this thread for more information.

    Update:

    You can aslo enable checkout submodule in the yaml, see here for more information.

    - checkout: self
      submodules: true