From my teamcity server I access a network share and create a msdeploy package/zip from a folder.
After this is done I create a Powershell Drive which is mapped to a shared folder of another server. This server is called GATE here.
<# CREATE DRIVE FOR GATE #>
$password = ConvertTo-SecureString "MyPassword" -AsPlainText -force
$credential = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList "MyUsername", $password
New-PSDrive -Credential $credential -Name GATE -PSProvider FileSystem -Root \\NetworkShare\sharedfolder
<# DEPLOY SOURCE FILE #>
Move-Item -Path $zipPath -Destination GATE:\data.zip
<# READ STATUS FILE #>
$statusContent = Get-Content GATE:\data.status.txt
The data.zip that is deployed is 1,5 GB zipped.
When I run Move-Item it takes a while till the 1,5 GB arrived at the server.
But my code on the teamcity side is continuing right after the Move-Item is executed.
And thats the problem I assume because the data.status.txt is only created on the GATE server when the file is really moved. The data.status.txt does not exist when I start to move the file, just AFTER it has been really moved.
How can I solve this dilema?
Use Copy-Item instead, and then just delete the source file.
Copy-Item will block script execution, while Move-Item does not.
Edit: Actually, as of PowerShell v 5.0, both cmdlets will block further script execution. Not sure if this was the case, previously.
Conclusion: If in testing, you find that Move-Item doesn't block, you can always use Copy-Item with -PassThru instead, which will always block.