我有一个构建创建.zip包和projectName.SetParameters.xml我希望用我的脚本覆盖projectName.SetParameters.xml文件中的参数
我有一个带有Mandotary参数的powershell脚本,我希望用户输入他们的用户名和密码,然后才能在TFS中部署到IIS我遵循本指南link 更新:REalese构建有效,但它不会要求用户输入用户名和密码,我是否必须在Powershell步骤的参数框内手动设置它们?
在我的TFS中我有一个powershell步骤我添加了参数-paramsFilePath C:/ somepath /.../.../ projectName.SetParameters.xml
param(
[string]$paramsFilePath,
[Parameter(Mandatory=$true)]
[string]$username,
[Parameter(Mandatory=$true)]
$password
)
Write-Verbose -Verbose "Entering script setParameters.ps1"
Write-Verbose -Verbose ("Path to Parameters: {0}" -f $paramsFilePath)
# get the environment variables
$vars = Get-ChildItem -path env:*
# read in the setParameters file
$contents = Get-Content -Path $paramsFilePath
# perform a regex replacement
$newContents = "";
$contents | % {
$line = $_
if ($_ -match "__Username__") {
$setting = Get-ChildItem -path env:* | ? { $_.Name -eq $Matches[1] }
if ($setting) {
Write-Verbose -Verbose ("Replacing key {0} with value from environment" -f $username.Name)
$line = $_ -replace "__Username__", $username.Value
}
}
$newContents = $line
}
Write-Verbose -Verbose "Overwriting SetParameters file with new values"
Set-Content $paramsFilePath -Value $newContents
Write-Verbose -Verbose "Exiting script setParameters.ps1"
这是我的Parameters.xml代码
<!--?xml version="1.0" encoding="utf-8" ?-->
<parameters>
<parameter name="machineURL" description="Please enter the name of the Environment" defaultvalue="_UrlValue_" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='machineURL']/@value">
</parameterentry>
</parameter>
<parameter name="username" description="Please enter the username" defaultvalue="__UserName__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='username']/@value">
</parameterentry>
</parameter>
<parameter name="password" description="Please enter the password" defaultvalue="__Password__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='password']/@value">
</parameterentry>
</parameter>
</parameters>
答案 0 :(得分:1)