azure-devops - 如何将预定义的管道构建参数传递给 Azure DevOps 管道中的模板?
问题描述
模板:
parameters:
- name: PathPrefix
displayName: 'Path prefix'
type: string
default: ''
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: ${{parameters.PathPrefix}}**/$(Build.DefinitionName).sln
管道:
resources:
repositories:
- repository: devops
name: foo/devops
type: git
ref: master
trigger:
branches:
include:
- refs/heads/*
jobs:
- job: Job_1
displayName: Agent job 1
pool:
vmImage: windows-latest
steps:
- checkout: self
- template: azure/pipelines/pipeline.yaml@devops
parameters:
PathPrefix: $(Build.DefinitionName)
在还原步骤中运行错误:
##[error]No files matched the search pattern.
即使设置verbosityRestore: detailed
恢复步骤也不会给我更多信息。
如果我不设置PathPrefix
,它似乎使用默认的空字符串并找到解决方案文件(在某些情况下)。但是,如果我确实设置了某些存储库中需要的前缀,它就找不到该文件。我尝试了各种在模板(${{}}
、$()
和$[]
其他)中引用参数的方法以及在管道中指定参数的不同方法,包括硬编码路径(尽管我想改用变量),但没有任何效果。
我想也许变量会起作用,所以我也尝试在管道中指定变量并在模板中使用它们,但这会导致同样的错误。在模板中定义变量给了我一个模板的编译错误(意外的标记“变量”或类似的东西)。
解决方案
看看你正在传递什么,并在心里扩展结果。
${{parameters.PathPrefix}}**/$(Build.DefinitionName).sln
如果Build.DefinitionName
是foo,并且你将它传递给 as PathPrefix
,那么你得到的是:
foo**/foo.sln
看起来你想要一个额外的正斜杠,所以你得到foo/**/foo.sln
.
推荐阅读
- python - 张量流错误:从分类列组成交叉列
- apache-kafka - 使用 Kafka Streams DSL 多次将同一主题用作源
- node.js - 如何修改mongodb/mongoose中私有路由的schema方法?
- c++ - 如何设置自定义小部件的背景颜色和边框宽度?
- android - SSL 证书固定在 Android 9 上不再工作
- vba - 收到电子邮件时运行的 Outlook 脚本仅在我将新邮件传输给自己时才有效
- ruby-on-rails - 将 Rspec 控制器测试从 Rails 4.2.10 迁移到 Rails 5.1.4 的问题
- django - Django 1.8 迁移输出
- azure-functions - EventGrid 订阅绑定通过 ngrok 工作到本地计算机,而不是 Azure 中的函数
- sql - SQL Server 和 ORACLE 之间的 SSIS 变量日期失败