-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
140 lines (140 loc) · 4.1 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
pipeline {
parameters {
booleanParam(name: 'release', defaultValue: true, description: 'Deploy build to github.io')
booleanParam(name: 'next', defaultValue: false, description: 'Deploy build to github.io (next)')
booleanParam(name: 'store', defaultValue: false, description: 'Store build')
password(name: 'GH_TOKEN', defaultValue: '', description: 'Github user token. Note: don\'t use a password, will be logged to console on error. Required for: deploy_io, release.')
choice(name: 'agent', description: 'Agent', choices: ['Linux', 'Win'])
choice(name: 'image', description: 'Docker Image', choices: ['node:10', 'node:11', 'node:12'])
gitParameter(name: 'BRANCH', branchFilter: 'origin.*?/(.*)', defaultValue: 'master', type: 'PT_BRANCH_TAG', useRepository: 'hub')
}
triggers {
// pollSCM('H/15 * * * *')
pollSCM('* * * * *')
}
agent none
stages {
stage('Cleanup') {
agent {
label params.agent
}
steps {
deleteDir()
}
}
stage('Build') {
when {
anyOf {
equals expected: true, actual: params.release
equals expected: true, actual: params.store
}
}
agent {
docker {
image params.image
label params.agent
}
}
environment {
BASE = "/hub-public/"
}
steps {
sh '''
yarn --no-lockfile && yarn build
'''
}
}
stage('Build (next)') {
when {
anyOf {
equals expected: true, actual: params.next
equals expected: true, actual: params.store
}
}
agent {
docker {
image params.image
label params.agent
}
}
environment {
BASE = "/hub-public/next/"
}
steps {
sh '''
yarn --no-lockfile && yarn build
'''
}
}
stage('Prepare: Store') {
when {
anyOf {
equals expected: true, actual: params.store
}
}
agent {
label params.agent
}
steps {
sh 'cd build && zip -r ../hub.zip *'
}
}
stage('Output') {
parallel {
stage('Release: Github IO') {
when {
equals expected: true, actual: params.release
}
agent {
label params.agent
}
steps {
sh '''
git clone -b master --single-branch https://github.com/studyathome-internationally/hub-public.git gh-pages
mv gh-pages/next next-backup
rm -rf gh-pages/*
cp -r build/* gh-pages/
mv next-backup gh-pages/next
cd gh-pages
git add .
git add -u .
git -c user.name='Mr. Jenkins' -c user.email='[email protected]' commit -m 'docs: release hub'
git push -f https://[email protected]/studyathome-internationally/hub-public.git
'''
}
}
stage('Release: Github IO (next)') {
when {
equals expected: true, actual: params.next
}
agent {
label params.agent
}
steps {
sh '''
git clone -b master --single-branch https://github.com/studyathome-internationally/hub-public.git gh-pages
rm -rf gh-pages/next/*
cp -r build gh-pages/next
cd gh-pages/next
git add .
git add -u .
git -c user.name='Mr. Jenkins' -c user.email='[email protected]' commit -m 'docs: release hub'
git push -f https://[email protected]/studyathome-internationally/hub-public.git
'''
}
}
stage('Store') {
when {
equals expected: true, actual: params.store
}
agent {
label params.agent
}
steps {
archiveArtifacts artifacts: 'hub.zip', fingerprint: true
}
}
}
}
}
}