如何修改 VSTS 发布管道中的应用程序清单?
How to modify the application manifest in VSTS release pipeline?
我必须在部署到集群时向应用程序清单 xml 文件添加额外的参数。在 VSTS 中配置了一个发布管道,我必须向其添加任务。
如何实现?我是否必须使用 Powershell 内联脚本?如果是这样,我该如何修改工件目录中的文件?
@Karthick,感谢您的回答,但我在保存 xml 时遇到问题。我确实将工作文件夹设置为 $(build.artifactstagingdirectory)
$appManifestFile = $(build.artifactstagingdirectory)\pkg\ApplicationManifest.xml
$xml = (Get-Content $appManifestFile) -as [Xml]
$newNode = $xml.CreateElement("Parameter")
$newNode.SetAttribute("Name","Test")
$newNode.SetAttribute("Value","Test")
Write-Host $newNode
$xml.ApplicationManifest.Parameters.AppendChild($newNode)
$xml.Save($appManifestFile)
如您所见,我是直接从工件中访问该文件,然后对其进行修改。该脚本在本地运行良好,但在管道中文件保持不变。我是不是漏掉了什么?
您可以使用构建事件来做到这一点How to: Specify Build Events (C#)
或
如果你想对 VSTS 构建管道做同样的事情,你可以添加一个强大的shell 构建步骤 by
1. 获取 路径 到您的工件放置位置
2. 将 路径 传递给您 shell 脚本
确保将工作目录设置为您的工件放置位置。这是 powershell 脚本将被执行的地方
- 您需要将目录作为变量传递给您的 PowerShell 脚本,这里是 'appManifestFile'
- PowerShell 脚本添加带有“$appManifestFile”作为 var 的追加节点
param
(
[string]$appManifestFile = ""
)
$appManifestFile = $appManifestFile + "\app.manifest"
echo "the path is set to : $appManifestFile"
$xml = (Get-Content $appManifestFile) -as [Xml]
$newNode = $xml.CreateElement("Parameter")
$newNode.SetAttribute("Name","Test")
$newNode.SetAttribute("Value","Test")
$xml.DocumentElement.AppendChild($newNode)
$xml.Save($appManifestFile)
我必须在部署到集群时向应用程序清单 xml 文件添加额外的参数。在 VSTS 中配置了一个发布管道,我必须向其添加任务。
如何实现?我是否必须使用 Powershell 内联脚本?如果是这样,我该如何修改工件目录中的文件?
@Karthick,感谢您的回答,但我在保存 xml 时遇到问题。我确实将工作文件夹设置为 $(build.artifactstagingdirectory)
$appManifestFile = $(build.artifactstagingdirectory)\pkg\ApplicationManifest.xml
$xml = (Get-Content $appManifestFile) -as [Xml]
$newNode = $xml.CreateElement("Parameter")
$newNode.SetAttribute("Name","Test")
$newNode.SetAttribute("Value","Test")
Write-Host $newNode
$xml.ApplicationManifest.Parameters.AppendChild($newNode)
$xml.Save($appManifestFile)
如您所见,我是直接从工件中访问该文件,然后对其进行修改。该脚本在本地运行良好,但在管道中文件保持不变。我是不是漏掉了什么?
您可以使用构建事件来做到这一点How to: Specify Build Events (C#)
或
如果你想对 VSTS 构建管道做同样的事情,你可以添加一个强大的shell 构建步骤 by
1. 获取 路径 到您的工件放置位置
2. 将 路径 传递给您 shell 脚本
确保将工作目录设置为您的工件放置位置。这是 powershell 脚本将被执行的地方
- 您需要将目录作为变量传递给您的 PowerShell 脚本,这里是 'appManifestFile'
- PowerShell 脚本添加带有“$appManifestFile”作为 var 的追加节点
param ( [string]$appManifestFile = "" ) $appManifestFile = $appManifestFile + "\app.manifest" echo "the path is set to : $appManifestFile" $xml = (Get-Content $appManifestFile) -as [Xml] $newNode = $xml.CreateElement("Parameter") $newNode.SetAttribute("Name","Test") $newNode.SetAttribute("Value","Test") $xml.DocumentElement.AppendChild($newNode) $xml.Save($appManifestFile)