-
Notifications
You must be signed in to change notification settings - Fork 11
/
Jenkinsfile
60 lines (58 loc) · 1.56 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
pipeline {
agent any
tools {
nodejs 'nodejs'
}
parameters {
choice(
description: '是否安装依赖?',
name: 'isInstall',
choices: ['false', 'true']
)
}
stages {
stage('install twelvet-react-ui') {
when {
expression { isInstall ==~ /(true)/ }
}
steps {
sh 'node -v'
sh 'rm -rf node_modules'
sh 'rm -rf yarn.lock'
sh 'yarn'
}
}
stage('Build prod') {
when {
beforeAgent true
branch 'master*'
}
steps {
sh 'rm -rf dist'
sh 'yarn build'
dir('dist') {
sh(script: 'tar cvzf twelvet-react-ui.tar.gz .', returnStatus: true)
archiveArtifacts artifacts: '**/*.tar.gz', fingerprint: true
}
}
}
}
}
node {
if (env.BRANCH_NAME.contains('master')) {
def remote = [:]
remote.name = 'twelvet'
remote.host = env.REMOTE_HOST
remote.port = 22
withCredentials([usernamePassword(credentialsId: 'twelvet', passwordVariable: 'password', usernameVariable: 'userName')]) {
remote.user = userName
remote.password = password
remote.allowAnyHosts = true
stage('push to twelvet-react-ui') {
sshPut remote: remote, from: 'dist/twelvet-react-ui.tar.gz', into: '/twelvet/docker/nginx/html/.'
sshCommand remote: remote, command: 'tar xvzf /twelvet/docker/nginx/html/twelvet-react-ui.tar.gz -C /twelvet/docker/nginx/html/'
sshCommand remote: remote, command: 'rm -rf /twelvet/docker/nginx/html/twelvet-react-ui.tar.gz'
}
}
}
}