0

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?

Elisabeth
  • 20,496
  • 52
  • 200
  • 321

1 Answers1

0

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.

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
  • and I guess executing XCopy did also block the script execution because I used this before the Move-item stuff and it worked compared to the Move-Item! – Elisabeth Oct 28 '15 at 22:10
  • Do you have a source for the claim that Copy-Item will block and Move-Item not? :-) – Elisabeth Oct 29 '15 at 09:24
  • Copy-Item solves one problem that on the GATE server when I access a large file I do not get an Access IO exception because the file is still IN Access so I do not have to use a stupid Sleep -Seconds 60 .... My main problem I have to solve with a while loop on teamcity polling the server for the data.status.txt, because this file is only created when the msdeploy on the GATE has pushed the package zip to another server. Yeah pretty confusing but thats the infrastructure hell of a enterprise community where they block all ports... – Elisabeth Oct 29 '15 at 11:40
  • I've tested and found that on PowerShell 5, both Cmdlets will block. If you've got an earlier version, simply use -Passthru, which will generate an object, which won't happen till the transfer is finished. Effectively instant blocking. :) – FoxDeploy Oct 29 '15 at 12:24
  • So I have use move-item with -passthru and its blocking? I need the deletion of the moved file because when I manually delete it then I get access errors... its still in access exception. – Elisabeth Oct 29 '15 at 14:55
  • Maybe something else has a handle to that file? If you still think that this is because of the filetransfer, you can always embed robocopy in your script, which will DEFINITELY super block until the file transfer is completed. – FoxDeploy Oct 29 '15 at 15:00