$SERVER = "8.140.221.49" $USER = "root" $KEY_PATH = "C:\Users\FZX\.ssh\FzxBdsh-ECS.pem" $PROJECT_PATH = "/opt/FzxBDSH" Write-Host "========================================" -ForegroundColor Cyan Write-Host " 风七六项目 Jenkins 部署脚本" -ForegroundColor Cyan Write-Host " 服务器: $SERVER" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan function Invoke-SshCommand { param( [string]$Command, [string]$Description ) Write-Host "" Write-Host "[$Description]" -ForegroundColor Yellow Write-Host "执行命令: $Command" -ForegroundColor Gray $sshArgs = @( "-i", $KEY_PATH, "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "$USER@$SERVER", "bash -c `"$Command`"" ) & ssh $sshArgs return $LASTEXITCODE } Write-Host "" Write-Host "1. 连接服务器并检查状态..." -ForegroundColor Green $exitCode = Invoke-SshCommand "echo '服务器连接成功'; hostname; date" "检查服务器连接" if ($exitCode -ne 0) { Write-Host "ERROR: 服务器连接失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "2. 进入项目目录并拉取最新代码..." -ForegroundColor Green $exitCode = Invoke-SshCommand "cd $PROJECT_PATH; git pull origin develop" "拉取最新代码" if ($exitCode -ne 0) { Write-Host "ERROR: 代码拉取失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "3. 构建Jenkins镜像..." -ForegroundColor Green $exitCode = Invoke-SshCommand "cd $PROJECT_PATH; podman-compose -f infrastructure/compose/podman-compose.aliyun-dev.yml build jenkins" "构建Jenkins镜像" if ($exitCode -ne 0) { Write-Host "ERROR: Jenkins镜像构建失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "4. 重启Jenkins服务..." -ForegroundColor Green $exitCode = Invoke-SshCommand "cd $PROJECT_PATH; podman-compose -f infrastructure/compose/podman-compose.aliyun-dev.yml up -d jenkins" "重启Jenkins服务" if ($exitCode -ne 0) { Write-Host "ERROR: Jenkins服务重启失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "5. 等待Jenkins启动..." -ForegroundColor Green Write-Host "Jenkins启动需要约3-5分钟,请耐心等待..." -ForegroundColor Yellow Start-Sleep -Seconds 120 Write-Host "" Write-Host "6. 验证Jenkins服务状态..." -ForegroundColor Green $exitCode = Invoke-SshCommand "podman ps -a --filter name=fzx-aliyun-jenkins" "查看Jenkins容器状态" if ($exitCode -ne 0) { Write-Host "ERROR: 容器状态检查失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "7. 检查Jenkins健康状态..." -ForegroundColor Green $exitCode = Invoke-SshCommand "curl -s http://localhost:8099/jenkins/api/json?tree=version 2>/dev/null || echo '健康检查中...'" "健康检查" Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host " Jenkins部署完成!" -ForegroundColor Green Write-Host " 访问地址: https://jenkins.fengzhongxing.com/jenkins/" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green