【发布时间】:2017-11-18 03:13:49
【问题描述】:
我在使用 Jenkins 运行远程脚本时遇到问题。我已经安装了 PowerShell 插件并且可以在本地构建服务器上运行 PowerShell 脚本,但是当我尝试在远程服务器上运行它时,它总是失败。我可以在 Jenkins 之外本地和远程运行相同的脚本,而且效果很好。我的假设是我缺少一个安全设置,但对于我的生活,我找不到它。
任何见解/帮助将不胜感激。
以下代码在服务器上使用 PowerShell 运行,但不通过 Jenkins:
$ErrorActionPreference = 'Stop'
# Create a PSCredential Object using the "User" and "Password" parameters
that you passed to the job
$SecurePassword = 'xxxxxxx' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList 'ci-user', $SecurePassword
# Invoke a command on the remote machine.
# It depends on the type of job you are executing on the remote machine as
to if you want to use "-ErrorAction Stop" on your Invoke-Command.
Invoke-Command -ComputerName xxx.xx.xx.xxx -Credential $cred -ScriptBlock {
# Restart the W32Time service
Restart-Service -Name W32Time
}
下面的错误是我在 Jenkins 中运行它时得到的。当我在 Jenkins 之外运行它并工作时,我使用相同的用户名和密码:
Connecting to remote server xxx.xx.xx.xxx failed with the
following error message : WinRM cannot process the request. The following
error with errorcode 0x8009030d occurred while using Negotiate authentication:
A specified logon session does not exist. It may already have been terminated.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are
specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does
not exist.
-The client and remote computers are in different domains and there is no
trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM
TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command:
winrm help config. For more information, see the about_Remote_Troubleshooting
Help topic.
At C:\Windows\TEMP\jenkins3589460126620702793.ps1:12 char:1
+ Invoke-Command -ComputerName xxx.xx.xx.xxx -Credential $cred -ScriptBlock {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (xxx.xx.xx.xxx:String) [], PSRemoting
TransportException
+ FullyQualifiedErrorId : 1312,PSSessionStateBroken
【问题讨论】:
-
你能把命令放在带有
Catch {$error[0]}的try / catch 块中吗?然后提供错误的输出?我还看到您使用的是 IP 地址而不是主机名,Don Jones 对this question 的回答可能是相关的。 -
我使用 Don Jones 的回答来设置远程环境,如果我在 Jenkins 之外使用 PowerShell 命令行界面运行脚本,该环境就可以工作。问题是当我在 Jenkins 中运行它时。我将发布错误...
-
ci-user是本地帐户还是域帐户?你使用domain\ci-user或servername\ci-user会发生什么?
标签: powershell jenkins