powershell脚本
# 全局终止设置方便捕获异常
$ErrorActionPreference = 'Stop'
# 隐藏进度条
$ProgressPreference = 'SilentlyContinue'
#下载jdk11并解压
Invoke-WebRequest -UseBasicParsing -OutFile "${TOOLS_DIR}/OpenJDK11U-jdk_x64_windows_hotspot_11.0.20.1_1.zip" "${DOWNLOAD_URL_GET_JDK}" Expand-Archive -Path "${TOOLS_DIR}/OpenJDK11U-jdk_x64_windows_hotspot_11.0.20.1_1.zip" -DestinationPath "${TOOLS_DIR}" -Force >> $null 2> $null
#判断文件夹是否存在
if (-not (Test-Path "${TOOLS_DIR}/jdk-11.0.20.1+1" -PathType container)) {
logger error 'install jdk fail'
exit 123
}
#判断文件是否存在
if (-not (Test-Path "$WORK_DIR/ciagent-${AGENT_ID}/springboot.jar" -PathType leaf)) {
logger error 'install agent.jar fail'
exit 123
}
# 删除压缩包
Remove-Item "${TOOLS_DIR}/OpenJDK11U-jdk_x64_windows_hotspot_11.0.20.1_1.zip" >> $null 2> $null
# 停止历史服务
logger debug "stop and delete old ci agent service if exists"
try {
#停止服务
Stop-Service "spring-${AGENT_ID}"
#删除服务
sc.exe delete "spring-${AGENT_ID}"
#删除文件
Remove-Item "$WORK_DIR/spring-${AGENT_ID}" -Recurse -Force >> $null 2> $null
}
catch {}
#创建文件夹
if (-not (Test-Path "${TOOLS_DIR}" -PathType container)) {
New-Item -ItemType Directory -Path "${AGENT_TOOLS_DIR}" >> $null 2> $null
}
#判断服务是否存在
$serviceStatus = Get-Service -Name ciagent-${AGENT_ID} -ErrorAction SilentlyContinue
if ($serviceStatus.Status -eq "Running") {
logger info "agent is installed!"
} else {
logger error "agent is not installed! check the log in ${WORK_DIR}/ciagent-${AGENT_ID}/logs"
}
我只想安静地学习,捡拾前人的牙慧,默默强大如此弱小的我...
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步