我准备了一个模板,可以在我的所有管道中重复使用它。看起来像这样:
stages:
- stage: Defender
displayName: Defender
pool:
vmImage: windows-latest
jobs:
- job: Scan
displayName: Scan
steps:
- task: MicrosoftSecurityDevOps@1
displayName: Microsoft Security DevOps
inputs:
config: ../configs/config.gdnconfig
文件夹结构如下所示:
- PROJ/ado-templates (root folder of template's repo)
- templates
- template.yml
- configs
- config.gdconfig
然后,在管道中我使用这个模板:
resources:
repositories:
- repository: templates
type: git
name: PROJ/ado-templates
stages:
- template: templates/microsoft-security.yml@templates
但是在扫描过程中我收到错误:
##[错误]ConfigurationPathNotFoundException:找不到配置文件:../configs/config.gdnconfig。这通常是由于尝试在尚不支持该工具的平台上使用该工具。 ##[错误]MSDO CLI 退出并显示错误退出代码:1
问题是,如何读取与此管道中使用的模板保存在同一存储库中的配置文件?
不要在管道中使用相对路径,而是尝试使用绝对路径,前面带有预定义变量,例如:
$(System.DefaultWorkingDirectory)/path/to/my/config.file
或者,作为替代方案:
$(Build.SourcesDirectory)/path/to/my/config.file
$(Build.SourcesDirectory)
和$(System.DefaultWorkingDirectory)
都指向代理上下载源代码文件的本地路径。