Sangeetha
Sangeetha

Reputation: 125

Connect to Windows server and copy items from Jenkins slave Workspace to c:/wwwroot/ powershell

I am using below PS script which will download Zip file from Nexus to Jenkins slave windows server.(Working as expected) My another task is to copy files from Jenkins windows server location to another windows server location.When I add this script in jenkins job i dont see any output nor errors. Please help me copy files which are zipped from Jenkins windows server to another windows server.

$ApplicationName="safenetws"
$clnt = new-object System.Net.WebClient
$url = "http://localhost:8081/$($env:VERSION)/$ApplicationName-$($env:VERSION).zip"
$file = "D:\Packages\$ApplicationName-$($env:VERSION).zip"
$clnt.DownloadFile($url,$file)
$session = new-pssession -computername $($env:SERVER) -credential $($env:PASSWORD)
$shell_app=new-object -com shell.application 
stop-WebSite -Name "SampleApp"
$items = $shell_app.NameSpace("D:\Packages\$ApplicationName-$($env:VERSION).zip\Content\C_C\Jenkins\workspace\Call\obj\Release\Package\PackageTmp\").Items()
$shell_app.NameSpace("D:\AppCode\wwwroot\SampleApp").CopyHere($items)
start-WebSite -Name "SampleApp"

Upvotes: 2

Views: 3122

Answers (1)

Kamal Gadepalli
Kamal Gadepalli

Reputation: 205

You can use any file transfer servers, like FTP, I have used FTP for the same requirement, By using ftp plugin in Jenkins, you can configure the source (Jenkins work space) to destination (other windows server). when the build is running it will copy the code from one location to other.

Upvotes: 1

Related Questions