forked from Platform-OS/platformos-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
159 lines (128 loc) · 3.98 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
@Library('pipeline-utils')_
def staging_url = "https://documentation-staging.staging.oregon.platform-os.com"
def production_url = "https://documentation.platformos.com"
pipeline {
agent any
environment {
MPKIT_TOKEN = credentials('POS_TOKEN')
MPKIT_EMAIL = "[email protected]"
}
parameters {
string(description: 'Instance URL. When empty then we deploy on staging and production', name: 'MP_URL', defaultValue: '')
}
options {
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
buildDiscarder(logRotator(daysToKeepStr: '1', artifactDaysToKeepStr: '1'))
}
stages {
stage('Build') {
when { branch 'master' }
agent { docker { image 'node:12-alpine'; args '-u root' } }
steps {
sh 'npm ci'
sh 'npm run build'
}
}
stage('Deploy to URL') {
when { expression { return !params.MP_URL.isEmpty() } }
environment {
MPKIT_URL = "${params.MP_URL}"
}
agent { docker { image 'platformos/pos-cli' } }
steps {
sh 'CI=true pos-cli deploy'
}
}
stage('Test on URL') {
when { expression { return !params.MP_URL.isEmpty() } }
agent { docker { image "platformos/testcafe" } }
environment { MP_URL = "${params.MP_URL}" }
steps {
sh 'npm run test-ci'
}
post { failure { archiveArtifacts "screenshots/" } }
}
stage('Deploy staging') {
when {
expression { return params.MP_URL.isEmpty() }
branch 'master'
}
environment {
MPKIT_URL = "${staging_url}"
}
agent { docker { image 'platformos/pos-cli' } }
steps {
sh 'CI=true pos-cli deploy'
}
}
stage('Test staging') {
when {
expression { return params.MP_URL.isEmpty() }
branch 'master'
}
environment {
MP_URL = "${staging_url}"
}
agent { docker { image "platformos/testcafe" } }
steps {
sh 'npm run test-ci'
}
post { failure { archiveArtifacts "screenshots/" } }
}
stage('Deploy production') {
when {
expression { return params.MP_URL.isEmpty() }
branch 'master'
}
environment {
MPKIT_URL = "${production_url}"
CI = true
}
agent { docker { image 'platformos/pos-cli' } }
steps {
sh 'pos-cli deploy'
}
}
// stage('Broken links checker') {
// when {
// branch 'master'
// expression { return params.MP_URL.isEmpty() }
// }
// agent { docker { image 'node:12-alpine'; args '-u root -v $HOME/tmp:/tmp' } }
// environment {
// MP_URL = "${production_url}"
// CI = true
// }
// steps {
// sh 'npm i broken-link-checker'
// sh 'time node ./scripts/check-broken-links.js'
// }
// }
}
post {
success {
script {
if (env.GIT_BRANCH == 'master') {
// testOutput = sh(returnStdout: true, script: 'cat $HOME/tmp/test-summary.txt').trim()
slackSend (channel: "#notifications-docs", color: '#00FF00', message: "SUCCESS: <${env.BUILD_URL}|Build #${env.BUILD_NUMBER}> - ${buildDuration()}. ${commitInfo()}")
// slackSend (channel: "#notifications-docs", color: '#00FF00', message: "${testOutput}")
}
}
}
failure {
script {
if (env.GIT_BRANCH == 'master') {
slackSend (channel: "#notifications-docs", color: '#FF0000', message: "FAILED: <${env.BUILD_URL}|Build #${env.BUILD_NUMBER}> - ${buildDuration()}. ${commitInfo()}")
}
}
}
}
}
def commitInfo() {
GITHUB_URL = "https://github.com/mdyd-dev/nearme-documentation"
commitSha = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
commitAuthor = sh(returnStdout: true, script: 'git log --format="%an" -1').trim()
commitMsg = sh(returnStdout: true, script: 'git log --format="%B" -1 ${commitSha}').trim()
return "<${GITHUB_URL}/commit/${commitSha}|${commitSha}> - ${commitMsg}"
}