I use github for hosting my projects and have multiple projects in github. And I use Azure devops for CICD alone. I have a single project in Azure devops, where I create individual pipeline corresponding to each project in my github repo. All these github projects would need to use the same azure-pipeline.yml for build. So instead of keeping the same yml file in each project, is there a way I can keep this yml centrally. So that in future, if at all a change is required, I need not do it for all individual projects, instead, update the main yml template.
A single yml file where I have all the code is even possible for my usecase? Any help is much appreciated
CodePudding user response:
Have you considered using templates? Essentially you have would end up with a single template containing the main build steps that is reusable and individual yaml for each pipeline that can pass parameters to the template for any differences you have between them (such as different triggers or variable values). This way you can update all pipelines by making changes to the template
CodePudding user response:
According to your description, you may setup a repo contains all the YAML files for pipelines. Kindly also be advised that we can also keep the templates in other repositories, if we have defined the repository resources
in the core YAML pipeline. Kindly refer to the sample Core and template YAML files below.
#Core YAML in Azure Repos
trigger: none
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: GitHub_REPO_1
type: github
name: GitHubAccountName/GitHubRepo1
endpoint: GitHubServiceConnectionName
- repository: GitHub_REPO_2
type: github
name: GitHubAccountName/GitHubRepo2
endpoint: GitHubServiceConnectionName
steps:
- checkout: none
# - checkout: GitHub_REPO_1
- template: GHREPO1.yml@GitHub_REPO_1
# - checkout: GitHub_REPO_2
- template: GHREPO2.yml@GitHub_REPO_2
#Template YAML from GitHub Repo
steps:
- script: echo "This YAML template is from GitHubRepo1"
displayName: 'Template From GitHubRepo1'
By the way, we could also checkout
the code from one or multiple repository resource(s) and trigger the pipeline by the commits from the repository resources. Please refer to the following documents for more information.
Define YAML resources for Azure Pipelines - Azure Pipelines | Microsoft Docs
Check out multiple repositories in your pipeline - Azure Pipelines | Microsoft Docs