【发布时间】:2019-04-11 11:17:25
【问题描述】:
我正在设置 GitLab CI/CD 管道以使用 PowerShell 复制项功能复制战争文件。我在管道中遇到错误。用户已经是 gitlab runner 计算机上的管理员。
[servername] Connecting to remote server name failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (servername:String) [], PSRemotingT ransportException + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken ERROR: Job failed: exit status 1
这是我在 .yml 文件中的脚本。
GitLab Runner 在 windows 服务器中注册。
这是我在 .yml 文件中的脚本。
envvariable_username - Environment variable configured in gitlab CI/CD settings page
$envvariable_password - Environment variable configured in gitlab CI/CD settings page
- powershell Invoke-Command -ComputerName computer_name -argumentlist $envvariable_username,$envvariable_password -ScriptBlock {
$password = convertto-securestring -String $envvariable_password -AsPlainText -Force
$mycred = new-object -typename System.Management.Automation.PSCredential $envvariable_username, $password
New-PSDrive -Name "s" -PSProvider FileSystem -root "\\\\computer_name\\share" -Credential $mycred
New-PSDrive -Name "z" -PSProvider FileSystem -root "\\\\computer_name\\backup" -Credential $mycred
Copy-Item -Path "s:\\sample.war" -Destination "z:\\sample.war"
}
预计将 .war 文件从一个服务器位置复制到另一个服务器位置
【问题讨论】:
-
Welcome to SO.. 错误消息中清楚地提到您收到拒绝访问。因此,请检查远程系统中路径的权限。以提升模式运行并检查
-
权限完好,用户是远程计算机上的管理员。如果我以管理员用户身份在命令提示符下运行,则相同的脚本可以工作文件。我们是否可以在我的 yml 文件中设置以管理员身份运行?
-
您正在调用 powershell.exe,然后是您的调用命令,并且您正在访问网络驱动器。您正在登陆DOUBLE HOP Issue。另外,您仍然可以使用
-RunAs -
感谢您的快速回复。我试过没有 powershell.exe 但没有用。低于errorbash:第52行:Invoke-Command:找不到命令
-
我在 gitlab CI 管道中运行 powershell 脚本。
标签: powershell gitlab