How to modify the application manifest in VSTS release pipeline?

谁都会走 提交于 2019-12-11 11:51:25

问题


I have to add additional parameter to application manifest xml file while deploying to cluster. There is a release pipeline configured in VSTS to which I have to add a task.

How to achieve this ? Should I have to use Powershell inline script ? If so how can I modify file in the artifact directory ?

@Karthick, Thanks for your answer , but I am facing issues while saving the xml. I did set the Working folder as $(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)

As you can see, I am accessing the file directly from the artifacts and then modifying it. This script works fine locally, but in pipeline the file remains unchanged. Am I missing out something?


回答1:


You can use the build events to do that How to: Specify Build Events (C#)

OR

If you wish to do the same with VSTS build pipeline, you can add a powershell buid step by

1. Get the path to your artifact drop location

2. Pass the path to your power shell script

make sure to set the working dir to your artifact drop location. This is where the powershell script will get executed

  1. You need pass the directory as a variable to your PowerShell script, here it is 'appManifestFile'

  2. PowerShell script to add append node with '$appManifestFile' as 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)


来源:https://stackoverflow.com/questions/49505735/how-to-modify-the-application-manifest-in-vsts-release-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!