背景

由于微信小工具的SDK是部署到Windows Server上的,在利用jenkins进行DevOPS的时候,就难免涉及到要将前端代码发送到Linux的生成服务器上去。那么问题就来了……

部署

环境

  1. 操作系统:Windows Server 2012R2 x64(2019以前都可以照此办理)
  2. 服务端: [OpenSSH For Windows]: https://github.com/PowerShell/Win32-OpenSSH/releases
  3. 工具: [Rsync客户端]: https://www.itefix.net/cwrsync

安装

# 下载OpenSSH客户端并解压至c:\windows\system32\,完整路径为c:\windows\system32\openssh
# 使用管理员权限打开powershell客户端
# 进入相应目录

# 安装SSHD服务
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

# 启动sshd服务
start-service sshd

# 设置自启动
Set-Service -Name sshd -StartupType 'Automatic'

# 添加防护墙规则
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Windows\System32\OpenSSH\sshd.exe"

# 修改默认SHELL为Powershell(可选)
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

# 安装rsync
# 解压cwrsync_6.2.4_x64_free.zip,将bin目录下除ssh、ssh-agent、ssh-keygen这几个文件外的所有文件复制到c:\windows\system32\openssh目录下

收尾

ps:在Jenkins使用Rsync时,需要加上全路径。