jenkins下后台运行链接Jenkins服务脚本方法

为了编写一个用于在后台运行 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:Jenkins agent 的 JNLP URL。

SECRET:Jenkins agent 的 secret。

WORK_DIR:Jenkins agent 的工作目录。

后台运行:

start /b 命令用于在后台运行指定的命令或程序。通过这种方式,Java 进程将以后台进程的方式启动。

可选等待:

REM wait %1 行是可选的。如果你希望脚本等待 Jenkins agent 进程完成,你可以取消注释这一行(在 Windows 中,wait 命令通常用于等待进程结束,但在批处理脚本中可能不是默认可用的命令,需要用其他方式来实现等待)。

将上述内容保存为 run_agent.bat 文件,然后双击运行这个批处理文件即可启动 Jenkins agent 并使其在后台运行。

相关推荐
回眸不遇6 小时前
类型的区别和应用场景 nested 每个对象独立存储为隐藏的子文档 适合存储数组 查询的时候有特定的语法 nested查询 且字段要 ...
运维·jenkins
X1A0RAN1 天前
容器化部署 Jenkins 教程
运维·docker·jenkins
BullSmall1 天前
jenkins 全局工具变更后,构建的任务为什么没有刷新过来
运维·jenkins
BullSmall1 天前
报错 libatomic.so.1: No such file or directory
jenkins
ji_shuke2 天前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
上海安当技术2 天前
老系统零改造接入:旁路代理统一认证实战
java·servlet·架构·kubernetes·jenkins
Mr. zhihao2 天前
Jenkins 从节点连不上主节点?一次网络排查全记录 + 机器间通信“拦截层“全景讲解
网络·servlet·jenkins
砍材农夫3 天前
运维|devops|jenkins构建分支选择及执行日志展示
运维·jenkins·devops
阿标在干嘛3 天前
政策快报平台日志系统的3次演进:从文件到ELK到告警
运维·elk·jenkins
worilb4 天前
Spring Cloud 学习与实践(16):Elasticsearch 商品搜索、中文分词与索引一致性
运维·jenkins