'How to add specific task from my common azure yml template? azure yaml

Problem to solve: I have my comon template which contain more then 5 task like #

-Task 1 -Task 2 ...

  • Task5

Possible solution: I want to refer that teample which is in other repositiry. but i dont want to refer all 5 task i just want to refer Task-1 not all 5

Problem of the solution: I want to know how i can re use only Task from other repository not whole tample

i have tried##

  • template:myyaml..yml@alias name but it call my all 5 taks where i just want to refer one task only


Solution 1:[1]

It seems you need to split your common yaml file that contains multiple tasks into several yaml files that contain a single task. You can then reference the individual task templates that you actually require in your main yaml file.

For example, split your single common template into multiple files like below

# File: template1.yml
steps:
- script: echo this is one templated task
# File: template2.yml
steps:
- script: echo this is another templated task

Then pick what ones you want to use in your main yaml file like so

pool: 
  vmImage: ubuntu-latest

resources:
  repositories:
    - repository: templates
      type: github
      name: Contoso/BuildTemplates

steps:
# Pick what templated tasks you want to use here
- template: template1.yml@templates  # Template reference
- template: twmplate2.yml@templates  # Template reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samuel