我在TFS 2015中有一个.Net应用程序。我已经配置了CI,并且工作正常。现在,我正在为应用程序配置CD。根据web.config文件中的变量,我需要选择我的部署路径。
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="ApplicationID" value="1" />
</appSettings>
</configuration>
例如:
if ApplicationID= 1 then my deployment path should be server1:\Deploy\abc
if ApplicationID= 2 then my deployment path should be server1:\Deploy\xyz
if ApplicationID= 3 then my deployment path should be server2:\Deploy\mns
if ApplicationID= 4 then my deployment path should be server2:\Deploy\bvc
如何配置此方案?
部署任务-Windows计算机文件复制。请建议是否需要更改任务。
答案 0 :(得分:1)
您可以添加一个PowerShell任务,该任务从XML中读取值,然后创建一个新的环境变量,其服务器路径取决于应用程序ID,在部署任务中,请使用以下变量:
[xml]$xmlObject = Get-Content "path/to/xml/file"
$appId = $xmlObject.configuration.appSettings.add.Where({ $_.key -eq "ApplicationID" }).value
$serverPath = ""
switch ($appId)
{
1 { $serverPath = "server1:\Deploy\abc" }
# Add here all the values
}
# Create the new variable:
Write-Host "##vso[task.servariable variable=serverPath]$serverPath"
现在在部署任务中使用变量$(serverPath)
。