首页 > 解决方案 > Windows 上的 Jenkins 无法使用 WinRM 部署?

问题描述

我有一个古老的代码库,我正试图将其提升到现代标准。其中大部分是使用 Visual Studio 在 Windows 上编写的,因此我需要一个基于 Windows 的构建服务器才能使用 MSBuild 管道。我有一个主要工作的 Jenkins CI 管道,它从 Github webhook 中提取,应该部署到我本地网络上的 Windows PC。我已经测试过这适用于我的工作站和构建服务器上的任何其他用户。我知道 Jenkins 以“NT AUTHORITY\System”用户身份运行作业,并且我过去曾使用 SysInternals PSExec 弹出并设置我的 ssh 密钥,等等。问题在于部署步骤;我正在使用 PowerShell 脚本压缩和复制构建输出,并使用New-PSSession, 和Copy-Item -ToSession.

我正在使用我正在使用 Get-Credential、用户/通行证对构建的凭据,我已验证该凭据可以正常工作。所有相关系统都在一个简单的工作组中,不涉及域。

我的 deploy.ps1 脚本中的New-PSSession命令失败并出现以下错误:

PS C:\Program Files (x86)\Jenkins\workspace\xxx> .\deploy.ps1

Compressing to C:\Windows\TEMP\tmpEBB2.tmp.zip
New-PSSession: C:\Program Files (x86)\Jenkins\workspace\xxx\deploy.ps1:95
Line |
  95 |  …     $sess = New-PSSession -ComputerName $TargetHost -Credential $cred …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | [205.208.87.185] Connecting to remote server 205.208.87.185 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.  Other Possible Cause:   -The domain or computer name was not
     | included with the specified credential, for example: DOMAIN\UserName or COMPUTER\UserName.
Write-Error: C:\Program Files (x86)\Jenkins\workspace\xxx\deploy.ps1:129
Line |
 129 |  Deploy-ToTargetHost
     |  ~~~~~~~~~~~~~~~~~~~
     | Could not establish session.

$sess当var 无法填充时,我生成了第二个错误。这是第 95 行:

$sess = New-PSSession -ComputerName $TargetHost -Credential $cred

我相信我听说过系统用户对网络访问有一些限制?有没有办法解决这个问题?

我的意思是,如果没有其他方法可以做到这一点,我可以将其 scp 完成,但如果我能侥幸逃脱的话,我真的很想把我所有的 shell 脚本都放在 pwsh 中。谢谢。

[编辑:TL;DR,我想我可以修改 Jenkins 以作为不同的用户运行,但为什么它还没有像那样运行?这对我来说似乎很奇怪,默认安装在没有网络访问权限的用户上,我猜?]

标签: windowspowershelljenkins

解决方案


我最终在 Windows 服务中以不同用户的身份运行 Jenkins,特别是“常规”登录用户。这使它成功地进行了部署。


推荐阅读