首页 > 解决方案 > Jenkins Job 将文件从 GIT 复制到 Windows 主机

问题描述

我必须实现一个 Jenkins 作业,我从 git 存储库访问文件并将它们复制到 Windows 服务器。我不能通过插件来做到这一点,需要使用 powershell 脚本。

我已经创建了下面的脚本,但它无法从 Jenkins 工作区中找到文件。我该如何执行此任务。

Jenkins Job Details:
Freestyle project
SCM - via git repository
Build Triggers: None
Build environement: Use secret text
Bindings: Specified usrname/password variable
Build : Windows power shell
Powershell script:

$loginPassword2 = ConvertTo-SecureString "$($ENV:loginPassword)" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ("$ENV:loginUsername", $loginPassword2)

Invoke-Command -ComputerName windows_Host_server -Credential $Credential -ScriptBlock {

Copy-Item .\Solr_config -Destination "E:\install" -recurse -For

}

错误:

Cannot find path 'C:\Users\****\Documents\Solr_config' because it
 does not exist.
    + CategoryInfo          : ObjectNotFound: (C:\Users\svc_**...nts\Solr_conf 
   ig:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyI 
   temCommand

标签: jenkins

解决方案


推荐阅读