Is it possible to nest yaml templates inside another yaml template ?
I've multiple NuGet projects in different Git repository, and I'm trying to template the process of publishing NuGets on nuget.org.
So I created a git repository named "devops-templates", did a first yaml template, be sure that it works, then divide it 4 yaml templates (build solution, generate packages, run unit tests, publish), and reference them into the global yaml template.
The problem is that when I tried to use this global template into my pipelines, I obtained errors
/Net/Utilities/BuildSolution.yml@templates (Line: 33, Col: 18): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 36, Col: 21): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 48, Col: 24): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 53, Col: 28): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 54, Col: 26): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 59, Col: 21): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 60, Col: 22): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 61, Col: 32): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 63, Col: 21): A template expression is not allowed in this context,/Net/Utilities/BuildSolution.yml@templates (Line: 64, Col: 26): A template expression is not allowed in this context
I searched inside Microsoft documentation : https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops but didn't find any information about it.
Here some parts of my code:
azure-pipelines.yml (main repository):
resources:
repositories:
- repository: templates
type: github
name: (...)/devops-templates
ref: refs/tags/v1.1.0
endpoint: (...)
stages:
- template: Net/Pipeline/NuGetsPipeline.yml@templates
parameters:
solution: $(solution)
nuGetsArtifactName: $(nuGetsArtifactName)
buildArtifactName : $(buildArtifactName)
(...)
NuGetsPipeline.yml (devops-templates repository):
parameters:
nuGetsArtifactName: 'NuGets'
buildArtifactName : 'Build'
nuGetSource: https://api.nuget.org/v3/index.json
solution: ''
(...)
stages:
- stage: Build
jobs:
- template: ${{variables['System.DefaultWorkingDirectory']}}/Net/Utilities/BuildSolution.yml
parameters:
buildArtifactName : ${{ parameters.buildArtifactName }}
(...)
- template: ${{variables['System.DefaultWorkingDirectory']}}/Net/Utilities/GenerateNuGets.yml
parameters:
nuGetsArtifactName: ${{ parameters.nuGetsArtifactName }}
buildArtifactName : ${{ parameters.buildArtifactName }}
(...)
- stage: 'UnitTests'
jobs:
- template: ${{variables['System.DefaultWorkingDirectory']}}/Net/Utilities/RunUnitTests.yml
parameters:
buildArtifactName : ${{ parameters.buildArtifactName }}
(...)
- stage: 'Publish'
jobs:
- template: ${{variables['System.DefaultWorkingDirectory']}}/Net/Utilities/PublishNuGets.yml
parameters:
nuGetsArtifactName: ${{ parameters.nuGetsArtifactName }}
(...)
BuildSolution.yml (devops-template repository):
parameters:
buildArtifactName: 'Build'
solution: ''
(...)
jobs:
- job: 'BuildSolution'
pool:
vmImage: ${{ parameters.vmImage }}
continueOnError: false
variables:
artifactName: ${{ parameters.buildArtifactName }}
steps:
- task: NuGetCommand@2
displayName: 'Restore NuGet packages'
inputs:
restoreSolution: ${{ parameters.solutionDir }}/${{ parameters.solution }}
configuration: ${{ parameters.buildConfiguration}}
- task: VSBuild@1
(...)
Edit : I added some parts of my code.