远程Powershell脚本和Jenkins不工作
我在使用Jenkins运行远程脚本时遇到问题。我已经安装了PowerShell插件,可以在本地生成服务器上运行PowerShell脚本,但是当我尝试在远程服务器上运行它时,它总是失败。我可以在Jenkins之外的本地和远程运行相同的脚本,而且效果很好。我的假设是,有一个安全设置我失踪,但我的生活,我找不到它 如有任何见解/帮助,将不胜感激 以下代码在服务器上使用PowerShell运行,但不是通过Jenkins运行:远程Powershell脚本和Jenkins不工作,powershell,jenkins,Powershell,Jenkins,我在使用Jenkins运行远程脚本时遇到问题。我已经安装了PowerShell插件,可以在本地生成服务器上运行PowerShell脚本,但是当我尝试在远程服务器上运行它时,它总是失败。我可以在Jenkins之外的本地和远程运行相同的脚本,而且效果很好。我的假设是,有一个安全设置我失踪,但我的生活,我找不到它 如有任何见解/帮助,将不胜感激 以下代码在服务器上使用PowerShell运行,但不是通过Jenkins运行: $ErrorActionPreference = 'Stop' # Crea
$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
这可能是由几个不同的问题造成的:
这可能是由几个不同的问题造成的:
我发现了自己的错误,但希望这个答案能帮助其他遇到错误的人 问题是我使用的用户是本地用户,需要将其视为工作组用户。因此,我需要将其作为\ci user传递,而不是ci user。一旦我这样做了,它就像一个符咒
谢谢你的所有意见。我发现了我的错误,但希望这个答案能帮助其他遇到它的人 问题是我使用的用户是本地用户,需要将其视为工作组用户。因此,我需要将其作为\ci user传递,而不是ci user。一旦我这样做了,它就像一个符咒
谢谢您的所有输入。您能将命令放入带有
catch{$error[0]}
的try/catch块中吗?然后提供错误的输出?另外,我发现您使用的是IP地址而不是主机名,Don Jones的答案可能与此相关。我使用Don Jones的答案来设置远程环境,如果我在Jenkins之外使用PowerShell命令行界面运行脚本,该环境将正常工作。问题是我在詹金斯的时候。我将发布错误…ci用户是本地帐户还是域帐户?使用domain\ci user
或servername\ci user
时会发生什么情况?能否将该命令放入带有catch{$error[0]}
的try/catch块中?然后提供错误的输出?另外,我发现您使用的是IP地址而不是主机名,Don Jones的答案可能与此相关。我使用Don Jones的答案来设置远程环境,如果我在Jenkins之外使用PowerShell命令行界面运行脚本,该环境将正常工作。问题是我在詹金斯的时候。我将发布错误…ci用户是本地帐户还是域帐户?使用domain\ci user
或servername\ci user
会发生什么情况?