Azure Devops:是否可以将Yaml模板嵌套在另一个Yaml模板中? [英] Azure Devops: Is it possible to nest yaml templates inside another yaml template?
问题描述
是否可以将Yaml模板嵌套在另一个Yaml模板中?
我在不同的Git存储库中有多个NuGet项目,并且我正在尝试对在nuget.org上发布NuGets的过程进行模板化.
因此,我创建了一个名为"devops-templates"的git存储库,做了一个第一个yaml模板,请确保它可以工作,然后将其划分为4个yaml模板(构建解决方案,生成包,运行单元测试,发布),并进行引用将它们放入全局yaml模板.
问题是,当我尝试在管道中使用此全局模板时,出现了错误
/Net/Utilities/BuildSolution.yml@templates(行:33,列:18):在这种情况下,不允许使用模板表达式,/Net/Utilities/BuildSolution.yml @ templates(行:36,Col:21):在此上下文中不允许模板表达,/Net/Utilities/BuildSolution.yml @ templates(Line:48,Col:24):在此上下文中不允许模板表达,/Net/Utilities/BuildSolution.yml@templates(第53行,列:28):在此情况下不允许使用模板表达式,/Net/Utilities/BuildSolution.yml @ templates(第54行,第26行:):在这种情况下不允许,/Net/Utilities/BuildSolution.yml @ templates(行:59,列:21):在这种情况下,不允许模板表达,/Net/Utilities/BuildSolution.yml @ templates(行:60,Col:22):在此上下文中不允许模板表达,/Net/Utilities/BuildSolution.yml @ templates(Line:61,Col:32):在此上下文中不允许模板表达,/Net/Utilities/BuildSolution.yml@templates(第63行,Col:21):在此上下文中不允许模板表达式,/Net/Utilities/BuildSolution.yml @ templates(Line:64,Col:26):在此上下文中不允许模板表达式
>
我在Microsoft文档中进行了搜索:https://docs.microsoft.com/zh-cn/azure/devops/pipelines/process/templates?view=azure-devops ,但未找到任何有关它的信息.
这是我的代码的某些部分:
azure-pipelines.yml(主存储库):
资源:仓库:-储存库:模板类型:github名称:(...)/devops-templates参考:refs/tags/v1.1.0端点:(...)阶段:-模板:Net/Pipeline/NuGetsPipeline.yml@templates参数:解决方案:$(solution)nuGetsArtifactName:$(nuGetsArtifactName)buildArtifactName:$(buildArtifactName)(...)
NuGetsPipeline.yml(devops-templates存储库):
参数:nuGetsArtifactName:'NuGets'buildArtifactName:生成"nuGetSource:https://api.nuget.org/v3/index.json解决方案: ''(...)阶段:-阶段:制作职位:-模板:$ {{variables ['System.DefaultWorkingDirectory']}}/Net/Utilities/BuildSolution.yml参数:buildArtifactName:$ {{parameters.buildArtifactName}}(...)-模板:$ {{variables ['System.DefaultWorkingDirectory']}}/Net/Utilities/GenerateNuGets.yml参数:nuGetsArtifactName:$ {{parameters.nuGetsArtifactName}}buildArtifactName:$ {{parameters.buildArtifactName}}(...)-阶段:"UnitTests"职位:-模板:$ {{variables ['System.DefaultWorkingDirectory']}}/Net/Utilities/RunUnitTests.yml参数:buildArtifactName:$ {{parameters.buildArtifactName}}(...)-阶段:发布"职位:-模板:$ {{variables ['System.DefaultWorkingDirectory']}}/Net/Utilities/PublishNuGets.yml参数:nuGetsArtifactName:$ {{parameters.nuGetsArtifactName}}(...)
BuildSolution.yml(devops模板存储库):
参数:buildArtifactName:生成"解决方案: ''(...)职位:-工作:"BuildSolution"水池:vmImage:$ {{parameters.vmImage}}ContinueOnError:假变量:artifactName:$ {{parameters.buildArtifactName}}脚步:-任务:NuGetCommand @ 2displayName:'还原NuGet软件包'输入:restoreSolution:$ {{parameters.solutionDir}}/$ {{parameters.solution}}配置:$ {{parameters.buildConfiguration}}-任务:VSBuild @ 1(...)
我添加了部分代码.
您的BuildSolution.yml中似乎存在缩进错误.参数和作业应具有相同的缩进.请参阅以下内容:
参数:buildArtifactName:生成"解决方案: ""职位:-工作:"BuildSolution"水池:vmImage:$ {{parameters.vmImage}}ContinueOnError:假变量:artifactName:$ {{parameters.buildArtifactName}}脚步:-任务:NuGetCommand @ 2displayName:'还原NuGet软件包'输入:restoreSolution:$ {{parameters.solutionDir}}/$ {{parameters.solution}}配置:$ {{parameters.buildConfiguration}}
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.
It seems like there is an indentation mistake in your BuildSolution.yml. parameters and jobs should have the same indentation. refer to below:
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}}
这篇关于Azure Devops:是否可以将Yaml模板嵌套在另一个Yaml模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!