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 并使其在后台运行。

相关推荐
GGG7662 天前
K8s1.28 全栈落地|Jenkins+GitLab+Harbor DevOps 流水线封神实战
kubernetes·gitlab·jenkins
叱咤少帅(少帅)3 天前
新版本jenkins的共享库的实现
运维·jenkins
2601_962297253 天前
Python、Pytest、Allure、Selenium和Jenkins实现自动化测试集成实例
python·selenium·jenkins·pytest·allure
大模型丫丫3 天前
工业级 RAG 为什么需要 Elasticsearch?
elasticsearch·django·jenkins
X1A0RAN4 天前
Jenkins 流水线跨阶段的数据共享:让变量“动态更新“成为可能
java·servlet·jenkins
Ningcode_cloud5 天前
什么是CICD? GitLab + Jenkins 持续集成实战部署手册
运维·ci/cd·云原生·容器·gitlab·jenkins
tianyuanwo5 天前
Jenkins 邮件插件选型指南:从命名原理到场景实践
jenkins·plugin·email
姚永强5 天前
安装Jenkins
运维·jenkins
成茂峰5 天前
实战:内外网隔离环境下基于 Jenkins + PowerShell 的自动化 CI 构建与邮件通知方案
ci/cd·自动化·jenkins
tianyuanwo5 天前
Jenkins Pipeline 沙箱与非沙箱:CPS、序列化与白名单的深度解读(含 `take()` 与 `subList()` 实战对比)
pipeline·jenkins·groovy·take·sublist