-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
153 lines (132 loc) · 3.09 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
#!groovy
def runNPM(command, nodeVersion) {
def NODE_VERSION = 14;
utilObj = new Utils();
envVersion = utilObj.getEnvVersion(nodeVersion ? nodeVersion : NODE_VERSION);
utilObj.runCmd(command, envVersion)
}
def runNPMInAllNodeVersion(command) {
def NODE_VERSIONS = [14, 16, 18];
NODE_VERSIONS.every(function(nodeVersion){
runNPM(command, nodeVersion);
});
}
def uploadAndInvalidate(environment) {
def STATIC_ASSETS = [
release: [
bucketName: credentials('DOCS_S3_BUCKET_NAME_PROD'),
cdnDistributionId: credentials('DOCS_S3_BUCKET_NAME'),
profile: 'prod'
],
staging: [
bucketName: credentials('DOCS_S3_BUCKET_NAME_STAGING'),
profile: 'staging'
]
]
uploadAssetsToS3('docs/dist', "s3://${STATIC_ASSETS[environment].bucketName}/api-sdk", 'us-east-1', true, false, 86400, STATIC_ASSETS[environment].profile)
if (environment == 'release') {
invalidateCDN(STATIC_ASSETS[environment].cdnDistributionId, '\"/*\"', STATIC_ASSETS[environment].profile)
}
}
def publishToNpm(environment){
if (environment == 'release') {
runNPM('npm run dopublish');
} else {
runNPM('npm run dopublish-dry-run');
}
}
pipeline {
agent {
kubernetes {
inheritFrom 'eks-node-executor'
}
}
environment {
NPM_TOKEN = credentials('NPM_TOKEN')
}
parameters {
choice(choices: 'None\nstaging\nrelease\ndeploydocs', description: 'Deploys docs to S3 bucket', name: 'deployTo')
}
stages {
stage('Checkout & Setup') {
steps {
checkout scm
runNPMInAllNodeVersion('npm ci')
}
}
stage('Run unit tests') {
steps {
runNPMInAllNodeVersion('npm test')
}
}
stage ('Remove target folder') {
steps {
sh 'rm -rf dist'
sh 'rm -rf docs/dist'
}
}
stage ('Build SDK') {
steps {
runNPM('npm run build:lib')
}
}
stage ('Build Docs') {
steps {
runNPM('npm run build:docs')
}
}
stage ('NPM publish dry-run') {
when {
expression {
params.deployTo == 'staging' || params.deployTo == 'release'
}
}
steps {
publishToNpm('staging')
}
}
stage ('Deploy docs to Staging') {
when {
expression {
params.deployTo == 'staging' && BRANCH_NAME == 'main'
}
}
steps {
uploadAndInvalidate('staging')
}
}
stage ('Deploy to Release') {
when {
expression {
params.deployTo == 'release' && BRANCH_NAME == 'main'
}
}
steps {
uploadAndInvalidate('release')
publishToNpm('release')
}
}
stage ('Deploy docs only') {
when {
expression {
params.deployTo == 'deploydocs' && BRANCH_NAME == 'main'
}
}
steps {
uploadAndInvalidate('release')
}
}
}
post {
always {
echo 'Freshworks API SDK job finished'
deleteDir()
}
success {
echo 'Freshworks API SDK job successful'
}
failure {
echo 'Freshworks API SDK job failed'
}
}
}