jenkins上添加项目配置

网上配置的没找到,自己记录一个方便后续添加

1.选择左上角新建任务

 2.选择流水线

 3.勾选丢弃旧的构建

 

 4.填写git仓库地址

 5.获取到Colone with SSH地址,把地址gitlab.asb.com改成ip形式的

 6.git授权用户,先在配置里找到需要设置的用户

 添加权限

 

7.在项目下添加Jenkinsfile和restart_dev.sh文件

 Jenkinsfile内容

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
40
41
42
43
pipeline {
    agent any
    tools {
        git 'git2u'
        maven 'm3'
    }
 
    stages {
        stage('build, send file to server') {
            tools {
                jdk "8u281"
            }
            steps {
                sh 'mvn -U clean install "-Dmaven.test.skip=true"'
                sh 'scp -P 登录时的端口 target/xxx.jar root@服务部署ip:xxx(项目位置绝对路径).jar_new'
                sh 'scp -P 登录时的端口 restart_dev.sh  root@服务部署ip:xxx(项目位置绝对路径)/restart_test.sh'
            }
        }
 
        stage('login server and deploy') {
            steps {
                script {
                    def remote = [:]
                    remote.name = '服务部署ip'
                    remote.host = '服务部署ip'
                    remote.port = 登录时的端口
                    remote.allowAnyHosts = true
                    remote.user ='root'
                    remote.identityFile = '/root/.ssh/id_rsa'
 
 
                        sshCommand remote: remote,
                        command: '''
                            cd 绝对路径
                            chmod +x ./restart_dev.sh
                            ./restart_dev.sh
                        '''
                        }
 
                     }
        }
    }
}

  restart_dev.sh

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash -e
 
cd 项目绝对路径
 
now=`date "+%Y%m%d%H%M%S"`
 
 
app_file='项目名称.jar'
 
 
 
app_new_file='项目名称.jar_new'
 
 
 
bak_file='./bak/项目名称.jar_bak'${now}
 
 
# 终止当前进程
 
printf "获取进程号...\n"
 
 
 
processId=`ps -ef | grep 项目名称.jar | grep -v "grep" | awk '{print $2}'`
 
 
if [ ! ${processId} = "" ]
 
 
then
 
 
    printf  ${processId}
 
 
 
    kill -9 ${processId}
 
 
 
    printf "进程已经停止\n"
 
 
 
else
 
 
 
   printf '进程不存在\n'
 
 
 
fi
 
 
 
printf "重命名文件...\n"
 
 
 
mv ./${app_new_file}  ./${app_file}
 
 
 
 
 
 
 
# 启动新版本
 
 
 
printf "启动项目....\n"
 
 
 
nohup java -Dspring.profiles.active=application的后缀名称 -jar 项目名称.jar >/dev/null 2>&1 &

  到此,Jenkins上配置服务已经完成,点击立即构建过段时间提示成功即可。

posted on   qqq9527  阅读(90)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示