为了编写一个用于在后台运行 Jenkins agent 的批处理脚本,你可以使用 start 命令来启动 Java 进程并将其设置为在后台运行。以下是一个示例批处理脚本 run_agent.bat:
bat
@echo off
setlocal
REM Set the path to the Jenkins agent JAR file
set AGENT_JAR_PATH=C:\path\to\agent.jar
REM Set the JNLP URL for the Jenkins agent
set JNLP_URL=http://127.0.0.1:8000/com/A40%5FU8/jenkins-agent.jnlp
REM Set the secret for the Jenkins agent
set SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
REM Set the working directory for the Jenkins agent
set WORK_DIR=D:\jenkins_home
REM Start the Jenkins agent in the background
start /b java -Xrs -jar "%AGENT_JAR_PATH%" -jnlpUrl "%JNLP_URL%" -secret "%SECRET%" -workDir "%WORK_DIR%"
REM Optional: Uncomment the following line if you want to wait for the process to finish
REM wait %1
echo Jenkins agent started in the background.
endlocal
设置变量:
AGENT_JAR_PATH:Jenkins agent JAR 文件的路径。
JNLP_URL