简体   繁体   English

Windows 上的 Jenkins 无法使用 WinRM 进行部署?

[英]Jenkins on Windows fails to deploy with WinRM?

I have an old established codebase that I'm trying to bring up to modern era standards.我有一个旧的代码库,我正试图将其提升到现代标准。 Most of it is written on Windows using Visual Studio, so I need to have a Windows based build server to use the MSBuild pipeline.其中大部分是使用 Visual Studio 在 Windows 上编写的,因此我需要有一个基于 Windows 的构建服务器才能使用 MSBuild 管道。 I have a mostly working Jenkins CI pipeline that ingests from Github webhooks, and should deploy to a Windows PC on my local.network.我有一个主要工作的 Jenkins CI 管道,它从 Github webhooks 摄取,并且应该部署到我的 local.network 上的 Windows PC。 I've tested that this works from any other user, on my workstation and on the build server.我已经在我的工作站和构建服务器上测试过这对任何其他用户都有效。 I know Jenkins runs jobs as the "NT AUTHORITY\System" user, and I've used SysInternals PSExec to pop in and setup my ssh keys, and so forth in the past.我知道 Jenkins 以“NT AUTHORITY\System”用户身份运行作业,而且我过去曾使用 SysInternals PSExec 弹出并设置我的 ssh 密钥,等等。 The problem is during the deploy step;问题出在部署步骤中; I'm compressing and copying the build output using a PowerShell script, and using New-PSSession , and Copy-Item -ToSession .我正在使用 PowerShell 脚本压缩和复制版本 output,并使用New-PSSessionCopy-Item -ToSession

I'm using a cred I'm constructing with Get-Credential, user/pass pair, that I've verified as working.我正在使用我正在使用 Get-Credential 用户/通行证对构建的信用,我已经验证它可以正常工作。 All concerned systems are in a simple workgroup, no domain involved.所有相关系统都在一个简单的工作组中,不涉及域。

The New-PSSession command in my deploy.ps1 script fails with the following error:我的 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.

I generated that second error when the $sess var fails to populate.$sess无法填充时,我生成了第二个错误。 This is line 95:这是第 95 行:

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

I believe I've heard something about the System user has some restrictions on.network access?我相信我听说过系统用户对网络访问有一些限制? Is there any way to work around this?有什么办法可以解决这个问题吗?

I mean, I can just scp it over if there's no other way to do this, but I really wanted to just have all my shell scripting in pwsh if I could get away with it.我的意思是,如果没有其他方法可以做到这一点,我可以将它 scp 过来,但我真的很想在 pwsh 中编写我所有的 shell 脚本,如果我可以摆脱它的话。 Thanks.谢谢。

[Edit: TL;DR, I suppose I can modify Jenkins to run as a different user, but why isn't it already running like that? [编辑:TL;DR,我想我可以修改 Jenkins 以作为不同的用户运行,但为什么它还没有像那样运行? This just seems trivially weird to me to install by default on a user with no.network access, I guess?]这对我来说似乎很奇怪,默认安装在没有网络访问权限的用户身上,我猜?]

I ended up running Jenkins as a different user in Windows Services, specifically a "regular" login user.我最终以 Windows 服务中的不同用户身份运行 Jenkins,特别是“常规”登录用户。 This made it do the deployment successfully.这使得它成功地完成了部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM