简体   繁体   English

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

[英]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的秘密变量,如下图所示:

TFS构建变量

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.

相关问题 tfs 2013 pass生成变量post build脚本powershell - tfs 2013 pass build variable post build script powershell 如何从TFS构建过程将参数传递给PowerShell脚本? - How to pass parameters to PowerShell script from TFS build process? 如何将参数从 powershell 脚本传递到 TFS 2013 构建? - How to pass parameters from a powershell script to TFS 2013 build? 将值从Powershell传递到TFS Build Workflow - Pass a value from powershell to TFS Build Workflow 尝试将管道秘密变量传递到 Powershell 脚本时出错 - getting error when trying to pass pipeline secret variable into Powershell script TFS:在Powershell脚本中访问在构建模板中使用的局部变量 - TFS: Access a local variable used in build template in a powershell script TFS构建powershell脚本步骤:无法访问$(Date:yyyyMMdd)变量 - TFS build powershell script step : Not able to access $(Date:yyyyMMdd) variable 在TFS生成过程中在PowerShell脚本中分配变量 - Assign variable in PowerShell script during TFS build process 用于构建 TFS 定义的 PowerShell 脚本 - PowerShell Script to Build TFS Definition 从 powershell 脚本中的变量中的 azure 密钥库获取秘密值 - Get secret value from azure key vault in variable in powershell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM