将秘密变量从TFS Build传递给Powershell脚本

Sun*_*ala 8 powershell tfsbuild continuous-deployment

我在我的构建定义中添加了名为Password的秘密变量,如下图所示:

TFS构建变量

我想在我的一个构建步骤中将密码传递给PowerShell脚本,如下图所示:

构建步骤

我的PowerShell脚本如下所示

 Param
(
    [Parameter(Mandatory=$true)]
    [string]$UserName,
    [Parameter(Mandatory=$true)]
    [string]$Password
)

$appPool = New-WebAppPool -Name "test"
$appPool.processModel.userName = $userName
$appPool.processModel.password = $password
$appPool.processModel.identityType = "SpecificUser"
$appPool | Set-Item
Run Code Online (Sandbox Code Playgroud)

但看起来密码的类型不是字符串.我尝试PSCredential但没有奏效.有人能帮助我吗?如何将密码从构建步骤传递给PowerShell脚本以及安全变量的类型?我无法直接读取环境变量,因为我在目标计算机上运行PowerShell脚本.因此,唯一的选择是将密码作为输入传递给脚本.

Sun*_*ala 14

最后我设法解决了这个问题.

通过powershell脚本参数发送密码时,我在密码周围加了双引号.繁荣!!它开始工作了.它发送解密的密码.

-UserName $(用户名)-Password"$(密码)"

我的power shell脚本保持与上面相同.

 Param
(
    [Parameter(Mandatory=$true)]
    [string]$UserName,
    [Parameter(Mandatory=$true)]
    [string]$Password
)

$appPool = New-WebAppPool -Name "test"
$appPool.processModel.userName = $userName
$appPool.processModel.password = $password
$appPool.processModel.identityType = "SpecificUser"
$appPool | Set-Item
Run Code Online (Sandbox Code Playgroud)