使用java -jar jenkins.war启动jenkins
1. Windows启动脚本,保存到jenkins.bat 后双击运行
@echo off
echo.
echo [信息] 使用Jar命令运行Web工程。
echo.cd %~dp0
rem
:: 设置jenkins数据主目录
set JENKINS_HOME=./jenkinsdataset JAVA_HOME=D:\Program Files\Java\jdk-11.0.15
set CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOMe%\lib\tools.jar;
set Path=%JAVA_HOME%\bin;
::-Dhudson.util.HttpResponseSplittingProtection=false -Djdk.http.headerSize=65536
set JAVA_OPTS=-Xms256m -Xmx2024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -Dhudson.util.ProcessTree.disable=truejava -jar %JAVA_OPTS% jenkins.war --httpPort=8081pause
2. linux启动脚本,保存到jenkins.sh
sh jenkins.sh
#!/bin/bash
export JENKINS_HOME="/jenkins/jenkins_war/jenkinsdata/"
JAVA_EXECUTABLE=/usr/local/java/jdk-17.0.2/bin/java
JENKINS_WAR=./jenkins.war
JENKINS_OPTS="--httpPort=8081"
$JAVA_EXECUTABLE -jar $JENKINS_WAR $JENKINS_OPTS
3. linux启动脚本,保存到jenkins.sh
sh jenkins.sh start
sh jenkins.sh stop
sh jenkins.sh restart
sh jenkins.sh status
AppName=./jenkins.war
export JENKINS_HOME="/jenkins/jenkins_war/jenkinsdata/"
JAVA_EXECUTABLE=/usr/local/java/jdk-17.0.2/bin/java
JENKINS_OPTS="--httpPort=8081"
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m"
APP_HOME=./
LOG_PATH=$APP_HOME/logs/$AppName.logif [ "$1" = "" ];
thenecho -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"exit 1
fiif [ "$AppName" = "" ];
thenecho -e "\033[0;31m 未输入应用名 \033[0m"exit 1
fifunction start()
{PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`if [ x"$PID" != x"" ]; thenecho "$AppName is running..."elsenohup $JAVA_EXECUTABLE $JVM_OPTS -jar $AppName $JENKINS_OPTS >$LOG_PATH 2>&1 &echo "Start $AppName success..."fi
}function stop()
{echo "Stop $AppName"PID=""query(){PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`}queryif [ x"$PID" != x"" ]; thenkill -TERM $PIDecho "$AppName (pid:$PID) exiting..."while [ x"$PID" != x"" ]dosleep 1querydoneecho "$AppName exited."elseecho "$AppName already stopped."fi
}function restart()
{stopsleep 2start
}function status()
{PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`if [ $PID != 0 ];thenecho "$AppName is running..."elseecho "$AppName is not running..."fi
}case $1 instart)start;;stop)stop;;restart)restart;;status)status;;*)esac