【问题标题】:Jenkins Amazon EC2 plugin WinRM infinite loopJenkins Amazon EC2 插件 WinRM 无限循环
【发布时间】:2021-01-22 11:47:19
【问题描述】:

我目前正在设置我的 Jenkins 服务器以在初始化构建时创建 EC2 实例。它完美地创建和销毁实例,但它不会与 WinRM 连接。目前,我已经在网上尝试了所有内容,总共使用了至少 16 个小时。

我尝试了一些事情:

Powershell 命令:

Enable-PSRemoting -Force
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'

尝试更改组策略以允许所有主机并启用不受信任的连接 尝试使用 powershell 和基本身份验证从我的本地计算机连接(完美运行) 尝试更改 jenkins 和 AWS 上的所有设置。 搜索了整个网络 将 EC2 插件从 5.1 降级到 4.2

我完全不知道自己能做什么。

下面这个输出是无限循环的:

Connecting to ******.eu-west-3.compute.amazonaws.com(52.47.***.**) with WinRM as 
administrator
Waiting for WinRM to come up. Sleeping 10s.

【问题讨论】:

    标签: jenkins amazon-ec2 winrm


    【解决方案1】:

    我刚刚完成了这个兔子洞的旅行,并设法让事情顺利进行。我的设置是 Jenkins 服务器 2.235.5 和 ec2-plugin 版本 1.55。我使用打包器构建了一个 AMI,配置了用户数据并启用了 smb。在 Jenkins 中,我将代理配置为使用 HTTPS 和自签名证书。代理使用为管理员帐户生成的密码。确保角色能够获取密码。

    打包器生成器

    "builders": [
        {
            "type": "amazon-ebs",
            "communicator": "winrm",
            "winrm_username": "Administrator",
            "winrm_use_ssl": true,
            "winrm_insecure": true,
            "user_data_file": "/opt/scripts/EC2UserData.ps1",
     ...
    

    Ec2UserData.ps1

    <powershell>
        write-output "Running User Data Script"
        write-host "(host) Running User Data Script"
    
        Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
    
        # Don't set this before Set-ExecutionPolicy as it throws an error
        $ErrorActionPreference = "stop"
    
        # Remove HTTP listener
        Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
    
        Enable-PSRemoting -force
        Set-Item WSMan:\localhost\Client\trustedhosts -value * -force
    
        # Create a self-signed certificate to let ssl work
        $Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer"
        New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force
    
        # WinRM
        write-output "Setting up WinRM"
        write-host "(host) setting up WinRM"
    
        cmd.exe /c winrm quickconfig -q
        cmd.exe /c winrm set "winrm/config" '@{MaxTimeoutms="1800000"}'
        cmd.exe /c winrm set "winrm/config/winrs" '@{MaxMemoryPerShellMB="1024"}'
        cmd.exe /c winrm set "winrm/config/service" '@{AllowUnencrypted="true"}'
        cmd.exe /c winrm set "winrm/config/client" '@{AllowUnencrypted="true"}'
        cmd.exe /c winrm set "winrm/config/service/auth" '@{Basic="true"}'
        cmd.exe /c winrm set "winrm/config/client/auth" '@{Basic="true"}'
        cmd.exe /c winrm set "winrm/config/listener?Address=*+Transport=HTTPS" "@{Port=`"5986`";Hostname=`"packer`";CertificateThumbprint=`"$($Cert.Thumbprint)`"}"
        cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
        cmd.exe /c netsh firewall add portopening TCP 5986 "Port5986"
        cmd.exe /c net stop winrm
        cmd.exe /c sc config winrm start= auto
        cmd.exe /c net start winrm
    
    </powershell>
    

    打包程序供应商

    "provisioners": [
        {
            "type": "file",
            "source": "/opt/config/jdk_11.0.2/cacerts",
            "destination": "c:\\temp\\cacerts"
        },
        {
            "type": "powershell",
            "scripts": [
                "/opt/scripts/InstallJava.ps1",
                "/opt/scripts/InstallJenkinsSlave.ps1",
                "/opt/scripts/EnableSmb.ps1"
            ]
        },
    

    安装Java.ps1

    wget 'http://javadl.oracle.com/webapps/download/AutoDL?BundleId=210185' -Outfile 'C:\jreinstaller.exe'
    Start-Process -filepath C:\jreinstaller.exe -passthru -wait -argumentlist "/s","INSTALLDIR=c:\Java\jre1.8.0_91"
    del C:\jreinstaller.exe
    Copy-Item "C:\Java\jre1.8.0_91\lib\security\cacerts" -Destination "C:\Java\jre1.8.0_91\lib\security\cacerts.original"
    Copy-Item "c:\temp\cacerts" -Destination "C:\Java\jre1.8.0_91\lib\security\cacerts" -Force
    $env:JAVA_HOME="c:\Java\jre1.8.0_91"
    setx PATH "$env:path;c:\Java\jre1.8.0_91\bin"
    

    安装JenkinsSlave.ps1

    # enable UserData to run on next launch
    cd C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts
    ./InitializeInstance.ps1 -Schedule
    
    Set-NetFirewallProfile -Profile Public,Private -Enabled False
    

    EnableSmb.ps1

    echo "Enabling smb1"
    
    #Enable SMB1 protocol to workaround Windows on-demand issues
    Enable-WindowsOptionalFeature -Online -FeatureName smb1protocol -NoRestart
    Set-SmbServerConfiguration -EnableSMB1Protocol $true -Confirm:$true -Force #may work on 2012 but not 2019
    set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters SMB1 -Type DWORD -Value 1 -Force
    #Just in case firewall really didn't get disabled
    Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
    
    echo "restarting lanman"
    Restart-Service lanmanserver
    

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 1970-01-01
      相关资源
      最近更新 更多