TFS-2017 - 添加输入用户名和密码的步骤
TFS-2017 - Add a step to enter Username and password
我有一个创建 .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>
TFS Build and Release 中的 PowerShell 执行只能在非交互模式下执行。构建和发布过程只会将执行结果流式传输到构建控制台。
You have to create a variable with the username. For the password you should use hidden variable:
Yes you have to place the arguments inside the argument box of the
PowerShell step
注意:密码字段看似安全且不可读,但隐藏变量的内容并不难读取。
创建变量并设置值。之后就可以在PowerShell步骤参数框中使用这个命令行参数了。
-paramsFilePath $(paramsFilePath) -username $(username) -password $(password)
我有一个创建 .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>
TFS Build and Release 中的 PowerShell 执行只能在非交互模式下执行。构建和发布过程只会将执行结果流式传输到构建控制台。
You have to create a variable with the username. For the password you should use hidden variable:
Yes you have to place the arguments inside the argument box of the PowerShell step
注意:密码字段看似安全且不可读,但隐藏变量的内容并不难读取。
创建变量并设置值。之后就可以在PowerShell步骤参数框中使用这个命令行参数了。
-paramsFilePath $(paramsFilePath) -username $(username) -password $(password)