templates - Azure DevOps 管道模板 - 如何连接参数
问题描述
整个下午,我一直在努力思考如何在 ADO 模板中连接一个参数。该参数是一个源路径,并且在模板中需要添加下一个文件夹级别。我想通过“简单”的连接来实现这一点。简化的模板采用参数并使用它来形成 PowerShell 脚本的 inputPath,如下所示:
parameters:
sourcePath: ''
steps:
- task: PowerShell@2
inputs:
filePath: 'PSRepo/Scripts/MyPsScript.ps1'
arguments: '-inputPath ''$(sourcePath)/NextFolder''
我尝试了各种方法来实现这种连接:
- '$(sourcePath)/NextFolder'
- 看上面
- '$(variables.sourcePath)/NextFolder'
- 我知道 sourcePath 不是变量,但尝试基于在任务条件中使用参数的事实,它显然仅在通过变量引用时才有效
- '${{ parameters.sourcePath }}/NextFolder'
和其他一些变化,都无济于事。我还尝试在模板中引入变量部分,但这是不可能的。
我在互联网上搜索了示例/文档,但没有直接的答案和其他问题似乎暗示了一些解决方案,但没有奏效。
如果有人可以帮助我,我一定会非常高兴。
提前谢谢。
解决方案
我们可以在我们的临时 yaml 文件中添加变量并将 sourcePath 传递给变量,然后我们就可以使用它了。这是我的演示脚本:
主要.yaml
resources:
repositories:
- repository: templates
type: git
name: Tech-Talk/template
trigger: none
variables:
- name: Test
value: TestGroup
pool:
# vmImage: windows-latest
vmImage: ubuntu-20.04
extends:
template: temp.yaml@templates
parameters:
agent_pool_name: ''
db_resource_path: $(System.DefaultWorkingDirectory)
# variable_group: ${{variables.Test}}
临时文件
parameters:
- name: db_resource_path
default: ""
# - name: 'variable_group'
# type: string
# default: 'default_variable_group'
- name: agent_pool_name
default: ""
stages:
- stage:
jobs:
- job: READ
displayName: Reading Parameters
variables:
- name: sourcePath
value: ${{parameters.db_resource_path}}
# - group: ${{parameters.variable_group}}
steps:
- script: |
echo sourcePath: ${{variables.sourcePath}}
- powershell: echo "$(sourcePath)"
推荐阅读
- apache-spark - 跨多个列搜索子字符串
- java - 使用 Jackson 将其反序列化为对象后,如何访问我的 GeoJSON 数据
- java - 数据库中的值每天递增一
- php - Symfony 4 - 将 VichUploader 与 Dompdf 一起使用?
- angular - Ionic 4 通过 GUI (ion-datetime) 自动更改日期设置
- c++ - 如何生成总和为 0.0 的 n 大小的随机浮点数组?
- javascript - 使用 JavaScript 在现有的本地 XML 中添加新元素
- spring-boot - Thymeleaf #aggregates.sum 具有多个条件
- dataframe - 从当前数据框的架构中为 Spark 数据框(在代码中)编写架构
- python - Nan在Python中没有辍学