我在Octopus部署中有一个powershell步骤,在部署网站之前从远程计算机上的zip文件中复制一些先决条件文件。
$source='\\RemoteMachine\Artifacts\ZipFile.zip\ChildFolder\FolderToCopy'
$target='C:\inetpub\wwwroot\Web';
if (!(Test-Path $target -PathType Container))
{
New-Item $target -Type Directory;
Write-Output "Created folder $target";
}
$shellApplication = New-Object -com shell.application;
$zipPackage = $shellApplication.NameSpace($source);
$targetFolder = $shellApplication.NameSpace($target);
Write-Output "Copying files...";
$targetFolder.CopyHere($zipPackage.Items())
Write-Output "Copy done";
但是,这似乎不起作用,我收到错误
You cannot call a method on a null-valued expression.
At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\c2f0444d-f099-49ce-ad17-a8aa47c4703b.ps1:15 char:1
+ $targetFolder.CopyHere($zipPackage.Items())
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
错误似乎指向CopyHere
行,当我将$zipPackage.Items()
更改为$zipPackage
时,PowerShell脚本会运行,但不会部署任何内容。
当我在机器上本地运行时,它似乎工作正常,但是当我通过章鱼部署运行相同的东西时,它不起作用