[英]Pass Secret Variable from TFS Build to Powershell script
I have added secret variable called Password in my build definition as shown in this image: 我在我的构建定义中添加了名为Password的秘密变量,如下图所示:
I want to pass the Password to the PowerShell script in one of my build steps as shown in this image: 我想在我的一个构建步骤中将密码传递给PowerShell脚本,如下图所示:
My PowerShell script looks like this 我的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
But it looks like the type of the Password is not a string. 但看起来密码的类型不是字符串。 I tried
PSCredential
but didn't work. 我尝试过
PSCredential
但没有奏效。 Can somebody help me? 有人能帮助我吗? How do I pass the password from build step to the PowerShell script and the type of the secure variable?
如何将密码从构建步骤传递给PowerShell脚本以及安全变量的类型? I can't read the environment variable directly because I am running the PowerShell script on a target machine.
我无法直接读取环境变量,因为我在目标计算机上运行PowerShell脚本。 So only option is to pass Password to the script as input.
因此,唯一的选择是将密码作为输入传递给脚本。
Finally I managed to solve it. 最后我设法解决了这个问题。
I have put double quotes around my Password when sending it via the powershell script arguments. 通过powershell脚本参数发送密码时,我在密码周围加了双引号。 Boom!!
繁荣!! it started working.
它开始工作了。 It sends the decrypted password.
它发送解密的密码。
-UserName $(Username) -Password "$(Password)"
-UserName $(用户名)-Password“$(密码)”
My power shell script stays the same as above. 我的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.