You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps Pipeline新手求助:经跳板机部署ASP.NET至AWS IIS

Azure DevOps Pipeline 部署ASP.NET应用至AWS Windows IIS(经跳板机)

针对你的场景,**优先用PowerShell + Windows远程管理(WinRM)**完成部署即可,无需额外依赖SSH/SCP(WinRM是Windows原生远程管理工具,适配性更强)。以下是分步操作指南:


第一步:配置跳板机与Web服务器的WinRM环境

因为要远程执行PowerShell命令,需先在两台Windows服务器上开启并配置WinRM:

  1. 登录跳板机(RDP),以管理员身份打开PowerShell,执行:
    # 启动WinRM服务并设置自动启动
    Start-Service WinRM
    Set-Service WinRM -StartupType Automatic
    # 快速配置WinRM允许远程连接
    winrm quickconfig -quiet
    # 将Web服务器IP/主机名加入信任列表
    Set-Item WSMan:\localhost\Client\TrustedHosts -Value "Web服务器IP/主机名" -Concatenate
    
  2. 同样在Web服务器上执行上述命令,将跳板机IP/主机名加入信任列表:
    Set-Item WSMan:\localhost\Client\TrustedHosts -Value "跳板机IP/主机名" -Concatenate
    
  3. 确保两台服务器的防火墙允许WinRM端口(默认5985 HTTP、5986 HTTPS)入站。

第二步:在Azure DevOps中配置加密变量与服务连接

  1. 创建加密变量组:
    进入项目设置 → 变量 → 变量组,创建包含以下保密变量的组:
    • JumpServerPassword:跳板机管理员密码
    • WebServerPassword:Web服务器管理员密码
  2. 创建WinRM服务连接(可选):
    若后续想简化Pipeline配置,可进入项目设置 → 服务连接 → 新建服务连接 → 选择「Windows远程管理」,分别配置跳板机和Web服务器的连接信息(IP/主机名、管理员账号、端口),保存为JumpServer-WinRM和WebServer-WinRM。

第三步:编写Azure DevOps Pipeline YAML

核心流程:拉取代码 → 构建ASP.NET应用 → 上传至跳板机 → 中转至Web服务器 → 部署到IIS

trigger:
- main # 替换为你的代码分支

pool:
  vmImage: 'windows-latest' # 使用微软托管的Windows代理(若需访问私有网络,需改用自托管代理)

steps:
# 1. 拉取GitHub代码(已关联GitHub则自动处理,未关联需先配置GitHub服务连接)
- checkout: self

# 2. 构建ASP.NET Web应用并打包
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: true

# 3. 上传构建包至跳板机临时目录
- task: PowerShellOnTargetMachines@3
  inputs:
    machines: '跳板机IP/主机名'
    adminUserName: '跳板机管理员账号'
    adminPassword: '$(JumpServerPassword)'
    scriptType: 'filePath'
    scriptPath: '$(Build.ArtifactStagingDirectory)\*.zip'
    targetMachineScriptPath: 'C:\Temp\app.zip'

# 4. 从跳板机中转至Web服务器,并完成IIS部署
- task: PowerShellOnTargetMachines@3
  inputs:
    machines: '跳板机IP/主机名'
    adminUserName: '跳板机管理员账号'
    adminPassword: '$(JumpServerPassword)'
    scriptType: 'inlineScript'
    inlineScript: |
      # 创建Web服务器的远程会话凭据
      $webCred = New-Object System.Management.Automation.PSCredential('Web服务器管理员账号', (ConvertTo-SecureString '$(WebServerPassword)' -AsPlainText -Force))
      $webSession = New-PSSession -ComputerName 'Web服务器IP/主机名' -Credential $webCred

      # 从跳板机拷贝构建包到Web服务器
      Copy-Item -Path 'C:\Temp\app.zip' -Destination 'C:\Temp\app.zip' -ToSession $webSession

      # 在Web服务器上执行部署操作
      Invoke-Command -Session $webSession -ScriptBlock {
        # 解压构建包到IIS站点目录
        Expand-Archive -Path 'C:\Temp\app.zip' -DestinationPath 'C:\inetpub\wwwroot\你的应用站点目录' -Force
        # 重启应用池确保更新生效
        Restart-WebAppPool -Name '你的应用池名称'
      }

      # 关闭远程会话
      Remove-PSSession $webSession

关键注意事项

  • 若Azure DevOps托管代理无法访问AWS私有网络,需在跳板机或同网络内部署自托管代理,并在Pipeline的pool中指定该代理。
  • 若偏好使用SSH/SCP,可在跳板机上安装OpenSSH服务,然后用Azure DevOps的SSH任务替代WinRM操作,但WinRM对Windows环境的IIS管理、服务操作兼容性更强。

内容的提问来源于stack exchange,提问作者Xstaci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 22:52:43