一、运行环境配置
1. 配置JAVA运行环境
安装JDK,并将java.exe(例如C:\Program Files\Java\jdk1.8.0_201\bin)所在路径加入环境变量Path
二. 启动agent连接server
1. 编辑并修改agent.ini
server=192.168.48.128
user_name=tangaoxiong
user_password=123456
agent_workspace=E:\JenkinsAgent
agent_name=hdq_win
agent_desc=agent of hdq win
agent_executors=1
agent_labels=HDQ WIN32
各字段说明:
image.png
2. 编辑agent.bat并运行启动agent
@echo ****************************************************************
@echo ******************AUTO START AGENT******************************
@echo ****************************************************************
::echo off
@if "%1" neq "debug" (
::is not debug mod, echo off
echo off
)
::java check
@call java -version
@if "%errorlevel%" neq "0" (
echo [ERROR]:can't execute command: "java", please install jdk and set "path" in environment variables
goto err_stop
)
::read config
@for /f "tokens=1,2 delims==" %%i in (agent.ini) do (
if "%%i"=="server" set server=%%j
if "%%i"=="user_name" set user_name=%%j
if "%%i"=="user_password" set user_password=%%j
if "%%i"=="agent_workspace" set agent_workspace=%%j
if "%%i"=="agent_name" set agent_name=%%j
if "%%i"=="agent_desc" set agent_desc=%%j
if "%%i"=="agent_executors" set agent_executors=%%j
if "%%i"=="agent_labels" set agent_labels=%%j
)
::check config
if "%server%" EQU "" (
echo [ERROR]:server can't be null
goto err_stop
)
if "%user_name%" EQU "" (
echo [ERROR]:user_name can't be null
goto err_stop
)
if "%user_password%" EQU "" (
echo [ERROR]:user_password can't be null
goto err_stop
)
if "%agent_workspace%" EQU "" (
echo [WARNNING]:agent_workspace is null, set it to %cd%
set agent_workspace=%cd%
)
if "%agent_name%" EQU "" (
echo [ERROR]:agent_name can't be null
goto err_stop
)
if "%agent_desc%" EQU "" (
echo [ERROR]:agent_desc can't be null
goto err_stop
)
if "%agent_executors%" EQU "" (
echo [ERROR]:agent_executors is not setted, set it to 1
set agent_executors=%%j
)
if "%agent_labels%" EQU "" (
echo [ERROR]:agent_labels can't be null
goto err_stop
)
echo server:%server%
echo user_name:%user_name%
echo user_password:%user_password%
echo agent_workspace:%agent_workspace%
echo agent_name:%agent_name%
echo agent_desc:%agent_desc%
echo agent_executors:%agent_executors%
echo agent_labels:%agent_labels%
::start agent
java -jar agent.jar -autoDiscoveryAddress %server% -username %user_name% -password %user_password% -fsroot "%agent_workspace%" -name %agent_name% -description "%agent_desc%" -executors %agent_executors% -labels "%agent_labels%"
::error handler
:err_stop
pause
启动成功示例:
image.png
三、配置任务
1. 登录Jenkins后台
2. 打开项目配置,勾选 “限制项目的运行节点”
3. 配置标签
在”标签表达式”中输入”HDQ && WIN32”,即指定同时具有标签”HDQ“和“WIN32”的打包机执行任务
image.png
网友评论