To use an Azure DevOps template from another repository, you'll need to create a new project or update an existing one to use the template. This involves specifying the repository URL and the path to the template file.
You can specify the repository URL by using the `template` parameter in your Azure DevOps YAML file. For example, if your template is stored in a repository called "templates" on Azure DevOps, you would use the URL "https://dev.azure.com/{organization}/{project}/_git/templates".
Once you've specified the repository URL, you can use the `template` parameter to reference the template file. For example, if your template file is called "mytemplate.yaml" and is located in the root of the repository, you would use the path "mytemplate.yaml".
Azure DevOps Pipeline Templates
Azure DevOps Pipeline Templates are a powerful tool for reducing code duplication and improving the security of your pipelines. Template expressions can be used to dynamically choose the branch of a repository resource, making it easier to manage different branches and versions of your code.
This feature was highly requested by the Developer Community, and it's now possible to specify the branch to check out for a repository resource using template expressions. You can use parameters and system predefined variables in your template expressions, but not YAML or Pipelines UI-defined variables.
With template expressions, you can write your pipeline to extend a template from a different branch or the same branch name as your pipeline, regardless of the branch you run it on. This makes it easier to evolve your template and pipelines independently.
You can also use template expressions to specify the version of a template to extend at build queue-time. This means your pipeline will extend the template in the same branch as the branch on which the pipeline runs.
Template Expressions
Template expressions in Azure DevOps are a game-changer for managing pipelines. They allow you to dynamically choose the branch of a repository resource, reducing code duplication and improving security.
You can use template expressions to specify the branch of a repository resource, making it easier to manage pipelines that build their own repository. For example, if your pipeline runs on the main branch, it can check out the main branch of the library repo.
Template expressions can be used in both repository and container resource definitions. This feature was highly requested by the Azure DevOps Developer Community.
You can now write YAML pipelines that use template expressions to choose the branch of a repository resource. This means you can specify the branch to check out for the library repository when running the pipeline.
Templates can be housed in their own repository, reducing coupling between the template and the pipelines that extend it. This makes it easier to evolve the template and the pipelines independently.
You can use parameters and system predefined variables in your template expressions, but not YAML or Pipelines UI-defined variables. This means you can customize your pipeline's behavior based on specific parameters or variables.
One popular use case for template expressions is to extend a template from a different branch or the same branch name as your pipeline. This allows you to keep your pipeline's and template's branches always matching.
Template Versioning
Template Versioning is a powerful feature that allows you to specify the version of a template to extend at build queue-time.
By doing so, your pipeline will extend the template in the same branch as the branch on which the pipeline runs, so you can make sure your pipeline's and template's branches always match.
You can choose to extend a template from a different branch by writing a specific YAML code, allowing you to have your pipeline on branch main extend a template from branch dev in one run, and extend a template from branch main in another run, without changing the code of your pipeline.
The ref property of a repository resource can use parameters and system predefined variables, but not YAML or Pipelines UI-defined variables when specifying a template expression.
In Resource Definitions
In Resource Definitions, you can specify a repository as the source for your Azure DevOps template. This allows you to reuse templates from other repositories.
To link a repository, you need to provide the repository URL and the branch or ref where the template is located. The repository URL should be in the format of https://dev.azure.com/{organization}/{project}/_git/{repository}.
Sources
- https://www.azuredevopslabs.com/labs/azuredevops/continuousintegration/
- https://prcode.co.uk/2020/10/14/azure-devops-pipeline-templates-and-external-repositories/
- https://www.linkedin.com/pulse/azure-devops-reference-pipeline-template-from-another-bhattacharjee-vy1bc
- https://blog.johnfolberth.com/terraform-ci-cd-azure-devops-and-yaml-templates/
- https://learn.microsoft.com/en-us/azure/devops/release-notes/2022/sprint-212-update
Featured Images: pexels.com