forked from Platform-OS/platformos-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
135 lines (106 loc) · 3.2 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
@Library('pipeline-utils')_
def staging_url = "https://documentation-staging.staging.oregon.platform-os.com"
def production_url = "https://documentation.platform-os.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: 10, unit: 'MINUTES')
buildDiscarder(logRotator(daysToKeepStr: '1', artifactDaysToKeepStr: '1'))
}
stages {
stage('Build') {
when { branch 'master' }
agent { docker { image 'node:10-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/marketplace-kit:2.0' } }
steps {
sh 'marketplace-kit 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'
}
}
stage('Deploy staging') {
when {
expression { return params.MP_URL.isEmpty() }
branch 'master'
}
environment {
MPKIT_URL = "${staging_url}"
}
agent { docker { image 'platformos/marketplace-kit:2.0' } }
steps {
sh 'marketplace-kit 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'
}
}
stage('Deploy production') {
when {
expression { return params.MP_URL.isEmpty() }
branch 'master'
}
environment {
MPKIT_URL = "${production_url}"
}
agent { docker { image 'platformos/marketplace-kit:2.0' } }
steps {
sh 'marketplace-kit deploy'
}
}
}
post {
success {
script {
if (env.GIT_BRANCH == 'master') {
slackSend (channel: "#notifications-docs", color: '#00FF00', message: "SUCCESS: <${env.BUILD_URL}|Build #${env.BUILD_NUMBER}> - ${buildDuration()}. ${commitInfo()}")
}
}
}
failure {
script {
if (env.GIT_BRANCH == 'master') {
slackSend (channel: "#notifications-docs", color: '#FF0000', message: "FAILED: <${env.BUILD_URL}|Open build details> - ${buildDuration()}")
}
}
}
}
}
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}"
}