Deploy artifacts without SMB

When doing release management one of the first step is to get the artifacts from your buildjob copied to a remote machine. TFS already have some buildin tasks like Windows machine File Copy or the Azure File Copy task

The Azure file copy task uses the Azure scripts to copy files to the Blob or to the VM itself( it actually copies the files through the Azure LOB storage)

The Windows Machine File copy is using robocopy so it is meant for copying locally through the SMB protocol. However you might be blocked by a firewall that wont allow SMB.

Then PowerShell comes to the rescue. (As always)

In PS5 the Copy-Item now contains a ToSession parameter, which allows us to copy through a PS remoting session. Quite cool.

You need to have PSRemoting enabled from the buildserver to the target server and have installed at least Powershell 5, before this works.

Then in your release add a Powershell task. e.g. inline script. Sample below

RM01

Any hidden variables like password, has to be provided as arguments, while others can be access in the script directly, like $env:Server

So now you are able to copy through the PSSession without enabling the SMB protocol.

Full sampleScript:

$Pass = ConvertTo-SecureString "$($args[0])" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($env:AdminUser, $Pass)
$Session = new-PSSession -ComputerName $env:Server -Credential $Cred

$Source = "$($env:SYSTEM_ARTIFACTSDIRECTORY)\$($env:BUILD_DEFINITIONNAME)\$($env:BUILD_BUILDNUMBER)\\*"
Write-Host "Copy from $($Source) to $($env:Server) at $($env:destinationFolder)"
Copy-Item $Source -Recurse -Force -Destination "$($env:destinationFolder)\" -ToSession $Session

Author: KimC

TFS admin and deployment fellow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s