【发布时间】:2019-10-27 13:10:22
【问题描述】:
我定义了一些构建定义变量,其中一些我作为秘密类型。
我正在尝试将秘密变量 $RPASS 传递给 TFS 上的内联 powershell 脚本任务,但它似乎不起作用。
我在这里看到了这篇文章:How to add secret variable as task environment variable in VSTS
但是,示例使用命令行。
是否可以在 powershell 内联任务中传递类似的参数?
$sec = New-Object -TypeName System.Security.SecureString
"$RPASS".ToCharArray()|%{$sec.AppendChar($_)}
$creds = new-object -typename System.Management.Automation.PSCredential -args "$env:USER", $sec
Send-MailMessage -From "tfs@domain.com" -Subject "YAY!" -To "user@domain.com" -Body "$env:DB_NAME" -SmtpServer server.com -Port 25 -Credential $creds
按照该帖子中的第二个答案,我尝试传入参数
$(RPASS)
然后改了这一行$arg[0].ToCharArray()|%{$sec.AppendChar($_)}
但这也没用
[错误]无法索引到空数组。
我尝试将它直接传递到脚本中:
$(RPASS).ToCharArray()|%{$sec.AppendChar($_)}
但这导致了错误:
+ ********.ToCharArray()|%{$sec.AppendChar($_)}
+ ~
An expression was expected after '('.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedExpression
2019-06-13T00:57:50.7974750Z ##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.
【问题讨论】:
标签: powershell tfs