2

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

forvaidya
  • 3,041
  • 3
  • 26
  • 33

1 Answers1

3

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
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Yes it is woking :) I have tested it on azure agents and agent hosted on laptop. Now I will test it on production environment. Can this checkout submodules gets translated in yml file or it is hidden inside in the server. – forvaidya Jun 26 '20 at 04:42
  • It can also be configured in yaml. Use `-checkout` set `submodules: true`. See [Checkout](https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout) – Levi Lu-MSFT Jun 26 '20 at 05:57
  • my pipeline worked after setting up submoules flag as suggested by you. However I did not se a corresponding change in yml file. Is there a way to tell this insruction to yml file – forvaidya Jun 26 '20 at 08:29
  • setup checkout submodule option on the UI page cannot be reflected on the yaml file. If you want enable checkout submodule in yaml file. You should add `-checkout` step in your pipeline, see above update. – Levi Lu-MSFT Jun 26 '20 at 08:36
  • I have already upvoted it, is there anyother button like "Accept" ? – forvaidya Jun 30 '20 at 11:03
  • @LeviLu-MSFT the `checkout: self submodules: true` yaml doesn't seem to work for an existing pipeline. I had to use the UI to enable it in the "Get sources" selection. Any idea how to avoid this? – georgiosd Jul 12 '20 at 07:34