DEV Community

Cover image for Multiple Repositories in a Single Azure Pipeline

Multiple Repositories in a Single Azure Pipeline

Davide 'CoderDave' Benvegnù on October 08, 2021

Did you know you can specify multiple repositories in one Azure DevOps YAML Pipeline and cause it to trigger by updates to any of the repositories?...
Collapse
 
evan_noronha_701680e94280 profile image
Evan Noronha

It is also good if you keep your YAML file in a separate repository from the application code and you want to trigger the pipeline every time an update is pushed to the application repository.

hey dude! I separated my yaml from my main source repo for this exact reason. But now, my source repo doesn’t seem to get build statuses attached to commits—only the yaml repo does. Have you encountered this? Do you know of a solution?

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

That's actually a good point... Let me see if there is a workaround for that.

Collapse
 
mohdemraan profile image
Mohammad Imran

Hey, were you able to find a solution for this? Do you also know what the "Related" column is for in the Sources pane on a run page of yaml based pipeline. I tried to search whole documentation but couldn't find any reference. I just shows "none" for the repo in which I keep the yaml file but nothing other application code repo. Don't know if this can be helpful somehow.

Thread Thread
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

No, I wasn't able to find any workaround. I also asked directly to the Azure DevOps product group and other MVPs but got no answers :(

On the "Related" it spells out Work-items and Artifact.
Work items will summarize the work items that are contained in the "build". How? It will analyze the commits you are builing and check the linked work items for those commits

Artifacts, instead, will summarize any build or pipeline artifact you publish in that pipeline

Thread Thread
 
andrewjw1995 profile image
Andrew Williamson

You can add a YAML file in your main source repository which extends from a template in your shared repository

Collapse
 
vishalgoyal_psl profile image
Vishal Goyal

@n3wt0n : Thanks for this lovely post. We have tried doing this on our side using our Azure DevOps Server collection / project.

We have 2 repositories A and B in same collection / project.

A has the application source code and B has the test scripts along with the yaml file for pipeline automation. When we do a code change to repo A, it does not trigger this pipeline. When we do code change to repo B, it does trigger the same pipeline. Below is snippet from Yaml file where "ExtenSURE_Data" is repo A and this yaml file sits in Repo B.

resources:
repositories:

  • repository: ExtenSURE_Data type: git name: ExtenSURE/ExtenSURE_Data ref: master trigger:
    • master

trigger:

  • main
  • master

jobs:

We have checked all settings, cannot find anything wrong.

What should we check / do.

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù • Edited

Uhm, it seems ok.

Can you try pasting the same snippet but with the right formatting?
Just paste it using the 3 backticks block

Image description

Collapse
 
vishalgoyal_psl profile image
Vishal Goyal

@n3wt0n : FYI - We tried this on Azure DevOps Services (cloud) and it worked. But does not work on Azure DevOps Server (On_premises). Seems we need to have something else done to make it work on ADO Server ?

Collapse
 
vishalgoyal_psl profile image
Vishal Goyal • Edited

'''
resources:
repositories:

  • repository: ExtenSURE_Data type: git name: ExtenSURE/ExtenSURE_Data ref: master trigger:
    • master

trigger:

  • main
  • master

jobs:
'''

Thread Thread
 
vishalgoyal_psl profile image
Vishal Goyal

ExtenSURE_Data - Name of the repository A
ExtenSURE - Name of the project under which we have both A and B repositories
Name of yaml file under repository B is azure-pipelines.yml

Collapse
 
pieronegri profile image
pieronegri

"It is also good if you keep your YAML file in a separate repository from the application code and you want to trigger the pipeline every time an update is pushed to the application repository."
...I was actually looking at that! I still do not get how to checkout multiple resources and finally push to only one of them via GIT command line inside azure devops...may you help?
Thanks a lot for the good stuff

Collapse
 
n3wt0n profile image
Davide 'CoderDave' Benvegnù

Hey, thanks.

If I understand correctly, you want to checkout from multiple repos and then push the whole thing to a single one?

Let's say you have 3 repo. Adding the 3 checkout instructions, one per repo, you will end up having the "3 parts" of code in:
/s/repo1
/s/repo2
/s/repo3

so what you'd need to do is simply make sure you are in the /s folder, and then do the "git magic" from there.

or, even better, you can make sure you checkout the destination repo first, in let's say /s/destination folder

then, checkout the other 3 repos in the same folder and you are ready to do git add ., commit, and push

Collapse
 
marncosta profile image
marncosta • Edited

"GitHub repos and other repos defined as resources cannot be used for triggering" I am trying to run a trigger into GitHUb and it is really not working. Have you also tried again?