问题
I need to execute the following script:
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
However I am getting this error:
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
回答1:
You need to pass the arguments to the script something like -Hostname $HostName
.
You can try using single quotes to escape the exception for the password containing Special Characters In PowerShell. ((
and {
here).
So, just try to set the value of the Password
variable something like this : 'b(!d_@{xxx'
Then try it again.
来源:https://stackoverflow.com/questions/50586953/how-to-use-vsts-variables-in-ftp-including-secure-variables