如何在FTP中使用VSTS变量,包括安全变量 [英] How to use VSTS Variables in FTP, including Secure Variables
本文介绍了如何在FTP中使用VSTS变量,包括安全变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要执行以下脚本:
Param(
[string]$HostName,
[string]$UserName,
[string]$Password,
[string]$SshHostKeyFingerprint,
[string]$RemoteFTPFolder,
[string]$GitUserEmail,
[string]$GitUserName,
[string]$PersonalAccessToken,
[string]$VSTSProjectName
)
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $HostName
UserName = $UserName
Password = $Password
SshHostKeyFingerprint = $SshHostKeyFingerprint
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
$session.GetFiles($RemoteFTPFolder+"/*", "D:\a\1\s\", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host "Download of $($transfer.FileName) succeeded"
}
Set-Location -Path "D:\a\1\s\"
git config --global user.email $GitUserEmail
git config --global user.name $GitUserName
git checkout master
git pull --rebase origin master
git add .
git commit -m "Changes done"
git push https://Personal%20Access%20Token:$PersonalAccessToken@mycompany.visualstudio.com/_git/$VSTSProjectName
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
我还创建了变量,有些是明文,有些像密码
I also created the variables, some are clear text, some are like passwords
但是我遇到此错误:
2018-05-29T14:25:41.4804626Z Error: The value supplied is not valid, or the property is read-only. Change the value, and then try again.
2018-05-29T14:25:41.5591148Z ##[error]Process completed with exit code 1.
它甚至不清楚失败的地方
And its not even clear where its failing
推荐答案
您需要将参数传递给脚本,例如-Hostname $HostName
.
You need to pass the arguments to the script something like -Hostname $HostName
.
您可以尝试使用单引号避开PowerShell中包含特殊字符的密码的异常. (此处为(
和{
).
You can try using single quotes to escape the exception for the password containing Special Characters In PowerShell. ((
and {
here).
因此,只需尝试设置Password
变量的值,如下所示:'b(!d_@{xxx'
So, just try to set the value of the Password
variable something like this : 'b(!d_@{xxx'
然后再试一次.
这篇关于如何在FTP中使用VSTS变量,包括安全变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文