Azure Devops - Muliple Repos Triggers - github

Has the Following Feature has been implemented for Gihub Repos yet?strong text
Multi-repo triggers
You can specify multiple repositories in one YAML file and cause a pipeline to trigger by updates to any of the repositories. This feature is useful, for instance, in the following scenarios:
You consume a tool or a library from a different repository. You want to run tests for your application whenever the tool or library is updated.
You keep your YAML file in a separate repository from the application code. You want to trigger the pipeline every time an update is pushed to the application repository.
With this update, multi-repo triggers will only work for Git repositories in Azure Repos. They don't work for GitHub or Bitbucket repository resources.
SAMPLE :
trigger:
main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release

As per Microsoft official sprint 173 updates 2020, this is achiveable using resources tag inside your yaml.
Here is an example that shows how you can setup an auto trigger inside your yaml pipeline based on any change in any other repos inside the same project and even other projects inside Azure DevOps as well.
Sample:
trigger:
- main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
In the above code snippet:
main branch in the self repo containing the YAML file
main or release branches in tools repo
Here is the link for official documentation form Microsoft for further details.
Hope that solution works for you.

Repository resource triggers only work for Azure Repos Git repositories in the same organization at present. They do not work for GitHub or Bitbucket repository resources.
Refer to this official doc for details: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
If you would like this feature to be supported, create a feature request: https://developercommunity.visualstudio.com/AzureDevOps/suggest

Related

Triggering an Azure pipeline from a repository in a different organization

I'm trying to set up a pipeline that will trigger, when a commit is made in a repository that exists in a different organization.
In my own org, I've created a git repo with a yaml pipeline file in the main branch.
With the below setup, I can checkout the code from the other organization if I run the pipeline manually. But it is not triggered when a commit is pushed to that repository.
Looking at the documentation, this should be possible?
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
resources:
repositories:
- repository: OtherOrgRepo # In a different organization
endpoint: OtherOrgConnection
type: git
name: proj/reponame
ref: develop
trigger:
- develop
pool:
vmImage: ubuntu-latest
steps:
- checkout: OtherOrgRepo
The token used for the service connection has full access.
Is this not supported, or am I missing a step?
I guess I just need to read the big blue box:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
Repository resource triggers only work for Azure Repos Git repositories in the same organization at present. They do not work for GitHub or Bitbucket repository resources.
I did however manage to trigger a classic pipeline by using a generic Git service connection, which will poll for changes at an interval.

Azure yml pipeline being triggered on change to repository resource used for templates

I currently have an Azure DevOps yaml file set up to release our project to its necessary environments. In this file, I reference a repository that holds our template files we use within the company.
resources:
repositories:
- repository: templates
type: git
name: 'Project/Repo'
ref: 'refs/tags/x.x.x'
trigger: none
What is odd is that today I made a change to the template repository, and it triggered a build in all our pipelines that use this repository as a resource. I have a trigger set to none, so why is it being triggered with a change to an outside repository?
Edit 1:
Adding an image to show some additional information

how can a git repository be automatically updated when imported to azure?

I have a git repository that has been imported to azure repos but when I make a new commit it doesn't reflect the new commit on azure, is there some config I need to enable to allow this?
Sorry if the question seems dumb but I have been navigating through the UI and I can't see how to achieve this
thank you for all your help
There are many ways to achieve your needs. You can refer to the sample I implemented using Azure pipelines(I assume your repository is imported from GitHub to azure repos):
1.Create a pipeline and choose your GitHub repo as source:
2.Here is my configuration of the yaml file:
trigger:
- '*'//This pipeline will run whenever you push an update to the GitHub repo
pool:
vmImage: 'windows-latest'
steps:
- task: gitmirror#0//You can install this task in marketplace
inputs:
GitRepoUrl: 'https://{PAT}#dev.azure.com/{Organization Name}/{Project Name}/_git/{Repo Name}.git'//This is the URL of Azure Repo, you need to add a personal access token in the URL
3.Now, when you update the files in GitHub, it will trigger the pipeline in Azure DevOps and then update your Azure repository.

Azure Devops YAML Pipeline Trigger on different repositories

Is it possible to have a yaml pipeline trigger on commits/PRs for branches of different repositories (e.g. Repo A) to the one the azure-pipelines.yaml file is in (e.g. Repo B)?
I'm aware I can build the pipeline against Repo B and have it checkout Repo A using e.g:
resources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
trigger:
- master
But the trigger is only applying to Repo B, i.e. when I make a commit on master to Repo A, the pipeline does not trigger.
The "Sprint 173" release seems to be including the multi-repo triggers feature. I suspect you might be missing the ref.
Here is an example that shows how to define multiple repository
resources in a pipeline and how to configure triggers on all of them.
trigger:
- main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
The pipeline in this example will be triggered if there are any
updates to:
main branch in the self repo containing the YAML file
main or release branches in tools repo
Unfortunately Multi-repo triggers is supported for Github repo resources yet.
As it is said in the document:
Repository resource triggers only work for Azure Repos Git repositories at present. They do not work for GitHub or Bitbucket repository resources.
If you were using Azure Repos Git repositories. You need to specify the trigger section for the repository resources in order to enable the Multi-repo triggers. See document here for more information.
Since you are using github, you can use pipeline completion triggers as workaround. You can refer to below steps to setup a pipeline completion trigger for RepoB pipeline.
1, Set up the triggering pipeline for RepoA.
You can create a pipeline for github RepoA in azure devops. Classic UI pipeline is recommanded, for it won't add a azure-pipelines.yaml file in your RepoA.
I suggest you add a empty agent job(without any tasks)in the triggering pipeline. So that the pipeline run will always be successful.
You need to Enable continuous integration for this triggering pipeline. So that the commits/PRs for branches in RepoA will automatically trigger this pipeline.
In the pipeline Edit page, Go to Triggers tab, Check Enable continuous integration, Add the branches you want to enable CI in the Branches Filters section
2, Set up pipeline resources in triggered pipeline (ie. azure-pipelines.yaml file for RepoB)
Add the pipeline resources and specify the trigger section in the pipeline resource. See below example:
resources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
pipelines:
- pipeline: repoAPipeline # Name of the pipeline resource
source: triggeringPipeline-RepoA # Name of the triggering pipeline
trigger:
branches:
- releases/*
- master
When changes are made to RepoA, the triggering pipeline will be triggered and complete successfully. When the triggering pipeline is completed, Pipeline for RepoB will be triggered.
By setting up the triggering pipeline for RepoA and the pipeline resources in pipeline of RepoB. You can achieve the same effect with Multi-repo triggers.

Reuse same build pipeline for different repository on Azure DevOps

I have a project on Azure DevOps containing multiple forks of the same main repository. I created a build pipeline for that repository which unfortunately cannot be reused for the present forks since a pipeline can only be configured for a single repository.
This solution is not ideal because leads to multiple identical pipelines, one for each fork, and maintaining all of them can be difficult.
Is there a way to use one pipeline for multiple repositories?
you can create a template file and reference that file from each pipeline, that way you can edit a single file and every pipeline will change.
example how to reuse a step file from different repo
resources:
repositories:
- repository: DevOps
type: git
name: DevOps
trigger: none
jobs:
- template: vsts/yaml/build.yaml#DevOps
parameters:
solutionName: xxx
registryName: yyy
You can take a look at the official docs for more examples
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops
It's on the roadmap for 2019 Q3:
Multi-repository support for YAML pipelines
https://dev.azure.com/mseng/AzureDevOpsRoadmap/_workitems/edit/1454026
Update: this is now implemented:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
"Triggers
You can trigger a pipeline when an update is pushed to the self repository or to any of the repositories declared as resources."