Referencing yml file from submodule in main pipeline

58 Views Asked by At

So I have an Azure DevOps pipeline which ha s a specific github repository and I’ve added the entire yml pipeline config in another github repo which is a submodule.

Unfortunately when I am trying to go to the main pipeline config file in order to select the path of of the yml from the submodule it seems that I cannot see the submodule in the tree.

Is there a possibility to be able to use the yml file from submodule in the main pipeline(which has a default repo). If yes what would be the steps?

Thank you

2

There are 2 best solutions below

2
Callum Daw On

If I'm understanding it right you have 2 repos, and want one of them to be able to reference a yml file in the other? For this to work the yml files need to be available at compile time, and this is totally possible!

Check out this info here about adding a repository resource to your pipeline (the main pipeline that will call the submodule) https://learn.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops&tabs=schema#define-a-repositories-resource

Once you have the reference, you can call submodules by appending the repository name to the path of the yml file, so Azure DevOps knows that it is from another repository, like this for example

Referencing the repo

resources:
  repositories:
  - repository: submodule
    type: github
    name: mygithub/submodule
    endpoint: my-github-service-connection
stages: 
- stage: myStage
  jobs:
  - template: source/Templates/Job/build.yml@submodule
    parameters:
      foo: bar

Hopefully I've understood the question correctly!

1
osim_ans On

If I understand correctly, you have two repositories: a main repository and a submodule repository containing a YAML config file.

Currently, your pipeline is configured to use the main repository as the source, which means you can't map the YAML file from the submodule repo for your pipeline definition.

If this is the case, then after changing the below setting, you should be able to access and view the YAML config file from the submodule repository for your pipeline definition. Make sure that the repository is set to 'submodule' under 'Get sources' settings, as shown in the second snippet.

  • Goto Triggers: enter image description here

  • Update the Repository to submodule: enter image description here

  • Now, you should be able to view and select the config yaml file from submodule: enter image description here