jenkins部署过程要点

cccs7 Lv5

jenkins 构建过程

源码管理

Git

1
2
3
4
5
6
7
8
无法连接仓库:Command "git ls-remote -h -- git@github.com:cs7eric/devs-phere.git HEAD" returned status code 128:
stdout:
stderr: No ED25519 host key is known for github.com and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

主要是因为 主机秘钥验证的问题

image-20250315174832566 image-20250315174922908

java

在 挂载目录安装 java,并在 全局工具配置中配置路径

maven

将maven的目录放置在 jenkins的 数据挂载目录里面,否则容器读不到

此外,要在 jenkins 的全局工具中 配置 maven 的路径以及 配置文件

构建时, 所指的 pom.xml 是相对路径

image-20250315200408322

若报错, permission denied ,则 执行 sudo chmod +x /var/jenkins_home/apache-maven-3.8.8/bin/mvn

publish over ssh

配置 ssh server

执行 shell 脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cp /var/jenkins_home/workspace/dev-sphere-subject/dev-sphere-subject/dev-sphere-subject-starter/target/dev-sphere-subject-starter.jar /var/jenkins_home/jar/

#!/bin/bash
APP_NAME=dev-sphere-subject-starter.jar
LOG_NAME=dev-sphere-subject.log



pid=`ps -ef | grep $APP_NAME | grep -v grep|awk '{print $2}'`

function is_exist(){
pid=`ps -ef | grep $APP_NAME | grep -v grep|awk '{print $2}'`
if [ -z ${pid} ]; then
String="notExist"
echo $String
else
String="exist"
echo $String
fi
}

str=$(is_exist)
if [ ${str} = "exist" ]; then
echo " 检测到已经启动的程序,pid 是 ${pid} "
kill -9 $pid
else
echo " 程序没有启动了 "
echo "${APP_NAME} is not running"
fi

str=$(is_exist)
if [ ${str} = "exist" ]; then
echo "${APP_NAME} 已经启动了. pid=${pid} ."
else
source /etc/profile
BUILD_ID=dontKillMe
nohup java -Xms300m -Xmx300m -jar /var/jenkins_home/jar/$APP_NAME >$LOG_NAME 2>&1 &
echo "程序已重新启动..."
fi
  • Title: jenkins部署过程要点
  • Author: cccs7
  • Created at : 2025-03-15 21:09:27
  • Updated at : 2025-03-15 21:14:23
  • Link: https://cs7eric.github.io/2025/03/15/jenkins部署过程要点/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
jenkins部署过程要点