-
Notifications
You must be signed in to change notification settings - Fork 20
/
Jenkinsfile
116 lines (115 loc) · 5.36 KB
/
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def gitUrl = "http://192.168.126.25/git/scri/our-dev-group/chartEditor.git "
def branch = "master"
def credentialsId = "c078ac92-89dd-4842-8292-5e348e68db08"
def rootPath= "./xslab-editor"
def rootPath_api= "./xslab-rearend"
def appName = "xslab"
def appName_api = "xslab-rearend"
def bakPath = "/home/jenkins_bak"
def putPath = "/home/jenkins_put"
def publishPath= "/usr/local/nginx/html/iplatform/xslab"
def publishPath_api= "/etc/soft/xslab-rearend"
def robot = "360ac2ce-efe5-4478-8703-7cd3bd463044"
pipeline {
agent any
stages {
stage('拉取代码') {
steps {
git branch: "$branch", credentialsId: "$credentialsId", url: "$gitUrl"
}
}
stage('项目编译') {
steps {
script{
sh "cd ${rootPath} && npm install && npm run build"
}
}
}
stage('项目部署') {
steps {
script {
def remote = [:]
remote.name = 'remote'
remote.host ='192.168.126.25'
remote.user = 'root'
remote.password ='kjjsyf#0512'
remote.allowAnyHosts= true
stage ('备份') {
sshCommand remote: remote,command: "mkdir -p ${bakPath}/${appName}"
sshCommand remote: remote,command: "mkdir -p ${bakPath}/${appName_api}"
sshCommand remote: remote,command: "mkdir -p ${publishPath}"
sshCommand remote: remote,command: "mkdir -p ${publishPath_api}"
sshCommand remote: remote,command: "cp -r ${publishPath} ${bakPath}/${appName}/${BUILD_NUMBER}"
sshCommand remote: remote,command: "cp -r ${publishPath_api} ${bakPath}/${appName_api}/${BUILD_NUMBER}"
}
stage ('更新') {
sshCommand remote: remote,command: "mkdir -p ${putPath}/${appName}"
sshPut remote: remote,from: "${rootPath}/dist",into:"${putPath}/${appName}"
sshPut remote: remote,from: "${rootPath_api}",into:"${putPath}"
}
stage ('启动') {
sshCommand remote: remote,command: "rm -rf ${publishPath}"
sshCommand remote: remote,command: "mv ${putPath}/${appName}/dist ${publishPath}"
sshCommand remote: remote,command: "\\cp -rf ${putPath}/${appName_api} ${publishPath_api}"
sshCommand remote: remote,command: "rm -rf ${putPath}/${appName_api}"
}
}
}
}
}
post {
success {
script {
dingtalk(robot: robot,
type: 'ACTION_CARD',
at: [],
atAll: false,
title: "",
text: [
"<font color=#0089ff >${appName}项目部署</font>",
"",
"----",
"",
"* 任务:#${BUILD_NUMBER}",
"* 项目:${appName}",
"* 状态:<font color=#00EE00 >部署成功</font>",
"* 持续时间:${currentBuild.durationString}".split("and counting")[0],
"* 执行人:${currentBuild.buildCauses.shortDescription}",
],
messageUrl: '',
picUrl: '',
singleTitle: '',
btns: [],
btnLayout: 'H',
hideAvatar: false
)
}
}
failure {
script {
dingtalk(robot: robot,
type: 'ACTION_CARD',
at: [],
atAll: false,
title: "",
text: [
"<font color=#0089ff >${appName}项目部署</font>",
"",
"----",
"",
"* 任务:#${BUILD_NUMBER}",
"* 项目:${appName}",
"* 状态:<font color=#EE0000 >部署失败</font>",
"* 持续时间:${currentBuild.durationString}".split("and counting")[0],
"* 执行人:${currentBuild.buildCauses.shortDescription}",
],
messageUrl: '',
picUrl: '',
singleTitle: '',
btnLayout: 'H',
hideAvatar: false
)
}
}
}
}