我这里举例上传到码云gitee
官网插件教程:https://gitee.com/help/articles/4193#article-header11

1、检查下载jenkins插件

前往Jenkins → Manage Jenkins →Manage Plugins将以下插件安装

Publish Over SSHDeploy to container Plugin

gitee

Maven Integration

Pipeline Maven Integration

jenkins pipeline clong 多个 git 仓库_Jenkins

2、Gitee配置

先获取Gitee API V5 的私人令牌(获取地址 https://gitee.com/profile/personal_access_tokens
将那一串数字复制了保存好

(1)前往 Jenkins → Manage Jenkins → Configure System → Gitee Configuration(Gitee配置)

jenkins pipeline clong 多个 git 仓库_jar_02

(2)点击添加,将私人令牌输入

jenkins pipeline clong 多个 git 仓库_linux_03


配置完成后测试连接

3、创建任务

(1)在Jenkins主页,点击图中所示位置

jenkins pipeline clong 多个 git 仓库_jar_04


(2)输入任务名称,不可以用中文,然后选择第一个,点击“确定”

jenkins pipeline clong 多个 git 仓库_git_05


(3)General(基础配置)

下图中的的Gitee连接是上面配置的

jenkins pipeline clong 多个 git 仓库_jar_06

(4)源码管理

URL是码云Gitee上面的仓库连接

jenkins pipeline clong 多个 git 仓库_Jenkins_07


点击“添加”按钮添加账号和密码

jenkins pipeline clong 多个 git 仓库_linux_08


(5)构建触发器

使用gitee插件

jenkins pipeline clong 多个 git 仓库_Jenkins_09


只要在浏览器上访问这个地址,该项目就会发起一次构建项目,即拉取代码打包部署操作,我们先把这个回调地址记下来往下滑,看到下图所示的位置,点击生成,会有一个Gitee WebHook密码,记下来。

jenkins pipeline clong 多个 git 仓库_git_10

(6)构建

clean install -Dmaven.test.skip=true -Ptest

jenkins pipeline clong 多个 git 仓库_Jenkins_11

(7)构建后操作

jenkins pipeline clong 多个 git 仓库_jar_12

4、Linux服务器配置

在linux服务器上,在上一步的cd /home/daima用vi命令新建两个脚本文件
stop.sh

#!/bin/bash
echo "Stop Procedure : demo-0.0.1-SNAPSHOT.jar"
pid=`ps -ef |grep java|grep demo-0.0.1-SNAPSHOT.jar|awk '{print $2}'`
echo '*旧的应用进程 pid:'$pid
if [ -n "$pid" ]
then
        kill -9 $pid
fi

start.sh

#!/bin/bash
echo 'Start the program : demo-0.0.1-SNAPSHOT.jar'
chmod 777 /root/.jenkins/workspace/mall_spring_boot/target/demo-0.0.1-SNAPSHOT.jar
export BUILD_ID=dontKillMe
echo '-------Starting-------'
cd /home/daima/
nohup java -jar /root/.jenkins/workspace/mall_spring_boot/target/demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=test >springBootLog.log 2>&1 &
echo '*启动成功'

然后给他们添加权限

chmod 777 * .

5、码云gitee配置

在WebHooks添加上回调码Gitee WebHook密码,然后保存

注意:gitee不可以使用ip地址作为回调码,所以得实现内网穿透。穿透后将http://192.168.101.177:8081换成内网穿透后的域名

回调地址中jenkins的“j”小写

jenkins pipeline clong 多个 git 仓库_git_13


保存后有一个请求历史,这样就可以了

jenkins pipeline clong 多个 git 仓库_Jenkins_14

之后上传代码到码云gitee,出现下图所示情况,表示成功

jenkins pipeline clong 多个 git 仓库_linux_15


jenkins pipeline clong 多个 git 仓库_Jenkins_16


jenkins pipeline clong 多个 git 仓库_linux_17


然后ip+项目的端口号即可访问,前提是必须打开项目端口的防火墙

jenkins pipeline clong 多个 git 仓库_linux_18