|
| 1 | +# This Azure Pipelines template is adds a prefix to the display name of each |
| 2 | +# task passed through the `stages` parameter. When used in conjunction with |
| 3 | +# an "extends" template which injects a lot of tasks into the pipeline, the |
| 4 | +# added prefix helps to identify which tasks were passed through this template |
| 5 | +# and which tasks were injected by the `baseTemplate`. |
| 6 | +# |
| 7 | +# This template assumes that `baseTemplate` uses the `stages` parameter. If it |
| 8 | +# doesn't, this template likely won't work as expected. |
| 9 | + |
| 10 | +parameters: |
| 11 | +# The pipeline will behave as if it were originally extended from this template, |
| 12 | +# except with updated task display names. |
| 13 | +- name: baseTemplate |
| 14 | + type: string |
| 15 | + default: "" |
| 16 | + |
| 17 | +# These parameters are passed directly to `baseTemplate` |
| 18 | +- name: templateParameters |
| 19 | + type: object |
| 20 | + default: null |
| 21 | + |
| 22 | +# These stages will be modified and passed to the `baseTemplate` as the |
| 23 | +# `stages` parameter. The |
| 24 | +- name: stages |
| 25 | + type: stageList |
| 26 | + default: [] |
| 27 | + |
| 28 | +# This prefix will be added to the display name of each task. |
| 29 | +- name: taskPrefix |
| 30 | + type: string |
| 31 | + default: "🟪" |
| 32 | + |
| 33 | + |
| 34 | +extends: |
| 35 | + template: ${{ parameters.baseTemplate }} |
| 36 | + parameters: |
| 37 | + ${{ insert }}: ${{ parameters.templateParameters }} |
| 38 | + stages: |
| 39 | + - ${{ each stage in parameters.stages }}: |
| 40 | + - stage: ${{ stage.stage }} |
| 41 | + ${{ each property in stage }}: |
| 42 | + ${{ if notIn(property.key, 'stage', 'jobs') }}: |
| 43 | + ${{ property.key }} : ${{ property.value }} |
| 44 | + jobs: |
| 45 | + - ${{ each job in stage.jobs }}: |
| 46 | + - job: ${{ job.job }} |
| 47 | + ${{ each property in job }}: |
| 48 | + ${{ if notIn(property.key, 'job', 'steps') }}: |
| 49 | + ${{ property.key }} : ${{ property.value }} |
| 50 | + steps: |
| 51 | + - ${{ each step in job.steps }}: |
| 52 | + # Special case for Azure Pipelines checkout task: |
| 53 | + # https://learn.microsoft.com/azure/devops/extend/develop/pipeline-decorator-context?view=azure-devops#task-names-and-guids |
| 54 | + # The checkout task does not have a name - it is special and built directly into the agent. |
| 55 | + # Avoid modifying the checkout task, or else it will show up in the UI as a task with no name. |
| 56 | + - ${{ if contains(step.task, '6d15af64-176c-496d-b583-fd2ae21d4df4') }}: |
| 57 | + - ${{ step }} |
| 58 | + - ${{ else }}: |
| 59 | + - task: ${{ step.task }} |
| 60 | + ${{ each property in step }}: |
| 61 | + ${{ if notIn(property.key, 'task', 'displayName') }}: |
| 62 | + ${{ property.key }} : ${{ property.value }} |
| 63 | + displayName: ${{ parameters.taskPrefix }} ${{ step.displayName }} |
0 commit comments