1. Install Jenkins
It is recommended to use Docker compose to install
Create a new docker-compose.yml script, modify relevant information, and execute the command docker-compose up -d in the script
version: '3.7'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
restart: unless-stopped
ports:
- '8082:8080'
- '50000:50000'
volumes:
- /mnt/data/jenkins_home/:/var/jenkins_home
- /mnt/data/maven/apache-maven-3.9.0:/usr/local/maven
- /usr/local/java-1.8.0-openjdk:/usr/local/java
- /mnt/data/maven/apache-maven-3.9.0/conf/settings.xml:/usr/local/maven/conf/settings.xml
networks:
- gljk
networks:
gljk:
driver: bridge
jdk and maven use host services.
2 access jenkins
Enter http://ip:8082 to access jenkins, and it prompts that it needs to be unlocked. The cloud server is deployed and configured with a security group for the relevant port and firewall configuration.
Go to /mnt/data/jenkins_home/secrets/initialAdminPassword to copy the password and log in
Select custom plugin, admin to continue
Click to get started!
3. Plug-in installation
Before installation, change the plug-in download address and upgrade site url: https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
to install the following plug-ins:
- Maven Integration
- Publish Over SS
- Fail The Build
- Ant Plugin
- GitLab Plugin
Global tool configuration (the path configured here is the path in the container)
target server configuration
When the project is automatically built, the packaged project will be transmitted to the target server via the network, and relevant information will be configured
modify time zone
4. New task
Enter the task name, select build maven project
configuration source code information
compilation configuration, the information configured here is about the editing details of the entire project, there are multiple sub-projects under the micro-service project, update does not need to update all sub-projects, all need to tell maven to edit the specific Serve.
Edit command: clean install -pl users -am -amd -Pdev -Dmaven.test.skip=true
parameter description:
-am --also-make builds the dependent modules of the listed modules at the same time;
-amd -also-make-dependents builds the modules that depend on the listed modules at the same time;
-pl --projects builds the specified modules, separated by commas;
-rf -resume-from Resume the reactor from the specified modules.
users is the name of the specified packaging service
The directory structure is as follows:
Compile the project separately, and the remote push will report an error later. Here, set the edit to a successful state. Save
the remote settings (be sure to find the directory location) and click Build
5. Related issues
Build console error: ERROR: Failed to parse POMs
Solution:
1. The maven warehouse directory may not have write permission, authorize the warehouse directory: chmod -R 775 [maven directory path]
2. For the microservice project, check whether there is a relativePath tag in the multi-module file, and delete the tag
6. Start script
Set execution permissions: chmod u+x users.sh
包文件路径及名称(目录按照各自配置)
APP_NAME=/mnt/data/huorantech_jar/users/users-1.0.0.jar
#日志文件路径及名称(目录按照各自配置)
LOG_FILE=/mnt/data/huorantech_jar/users/users.log
#查询进程,并杀掉当前jar/java程序
pid=`ps -ef|grep $APP_NAME | grep -v grep | awk '{print $2}'`
kill -9 $pid
echo "$pid进程终止成功"
sleep 2
#判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
if test -e $APP_NAME
then
echo '文件存在,开始启动此程序...'
# 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
nohup java -jar $APP_NAME > $LOG_FILE 2>&1 &
#企业微信机器人通知配置
date=$(date +%Y-%m-%d)
time=$(date "+%H:%M:%S")
content="**更新通知**
>Time:$date.$time
>Info:"用户服务更新成功"
"
webHookUrl="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?xxx"
content='{"msgtype": "markdown","markdown": {"content": "'$content'","mentioned_list":"@all"},}'
echo "content : $content"
curl --data-ascii "$content" $webHookUrl
echo "over!"
#实时查看启动日志(此处正在想办法启动成功后退出)
#tail -f $LOG_FILE
#输出启动成功(上面的查看日志没有退出,所以执行不了,可以去掉)
#echo '$APP_NAME 启动成功...'
else
echo '$APP_NAME 文件不存在,请检查。'
fi