我们正在使用扩展功能以安全的方式重用我们管道中的模板。为了更容易地定义模板的参数,我想使用变量,但我觉得这是不可能的。
但由于我在本轮中询问的官方文档中找不到答案。
我的 yml 文件如下所示:
std::shared_ptr
当我尝试运行它时出现以下错误:
name: '[$(Date:yyyyMMdd).$(Rev:r)][$(Build.SourceBranchName)]'
# ========================================================================
# Pipeline Triggers
# ========================================================================
schedules:
- cron: "0 22 * * *" # time in UTC timezone
displayName: Daily midnight build for mainline branches
branches:
include:
- develop
- master
always: true
- cron: "0 22 * * *" # time in UTC timezone
displayName: Daily midnight build for release branches
branches:
include:
- release/*
always: false
# ========================================================================
# Template resource
# ========================================================================
resources:
repositories:
- repository: templates # id for reuse in below script code
type: git
name: Tools/pipeline-templates
ref: develop
variables:
Test: TestGroup
# ========================================================================
# Template reference
# ========================================================================
extends:
template: template.yml@templates # Template reference
parameters:
Param1:
- "-T test"
我觉得由于我们的模板也使用了变量,所以不能在根 yml 文件中使用。
谢谢
答案 0 :(得分:0)
您的意思是要使用变量来帮助您定义模板参数吗? 如果是,我们建议您可以使用 ${{variables.VariableName}}
这是我将阶段更改为关键字(扩展)的演示脚本:
resources:
repositories:
- repository: templates
type: git
name: Tech-Talk/template
trigger: none
variables:
- name: Test
value: TestGroup
pool:
vmImage: ubuntu-latest
extends:
template: temp.yaml@templates
parameters:
agent_pool_name: ''
db_resource_path: $(System.DefaultWorkingDirectory)
variable_group: ${{variables.Test}}
这是我的 temp.yaml:
parameters:
- name: 'variable_group'
type: string
default: 'default_variable_group'
- name: agent_pool_name
default: ""
- name: db_resource_path
default: ""
stages:
- stage:
displayName: ${{parameters.db_resource_path}}
variables:
- group: ${{parameters.variable_group}}
jobs:
- job: READ
displayName: Reading Parameters
steps:
- script: |
echo variable_group: ${{parameters.variable_group}}
- powershell: echo "$(ServiceConnection)"
附上新的测试结果:可以发现变量TestGroup已经传给了temp yaml: