首页 > 解决方案 > 如何在构建工件中引用文件

问题描述

我有一个从构建管道创建的发布管道。创建的工件具有 PowerShell 函数 - 该函数基于 template.json 文件在 Azure 中部署一组资源组。所以我需要执行 New-AzDeployment 并从构建工件中传入 template.json。

我试过使用 $(Build.SourcesDirectory) 和其他变量,但是 powershell 错误,因为它不知道那是什么

New-AzDeployment -Name "resourceGroupDeployment" `
                 -TemplateParameterFile "$(Build.SourcesDirectory)/resourceGroup.Parameters.json" `
                 -TemplateFile "$(Build.SourcesDirectory)/resourceGroup.Template.json" `

标签: powershellazure-devops

解决方案


有关发布管道中可用的默认变量,请参见此处。

您正在寻找的是$(System.ArtifactsDirectory)变量。所以你会有类似的东西"$(System.ArtifactsDirectory)\<artifact_alias>\resourceGroup.Template.json"

<artifact_alias>是将工件添加到发布管道时设置的工件源别名。


推荐阅读