This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Jenkinsfile
145 lines (126 loc) · 4.46 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
pipeline {
agent none
options { timestamps() }
stages {
stage('Input') {
when {
branch 'master'
beforeInput true
}
steps {
script {
env.DEPLOY_CLIENT = input \
message: 'Would you like to deploy the client to NPM?', \
parameters: [choice(name: 'DEPLOY_CLIENT', choices: ['Yes', 'No'], description: '')]
}
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
agent { label 'linux-slave' }
steps {
sh "npm install"
sh "npm run test:unit -- --noColor -x \"--no-cache --verbose\""
sh "npm run check -- --noCache"
}
post {
always {
junit "dist/test/results-unit.xml"
}
}
}
stage('Integration Tests') {
agent { label 'win10-dservices' }
steps {
bat "npm install"
bat "npm run test:int -- --noColor -x \"--no-cache --verbose\""
}
post {
always {
junit "dist/test/results-int.xml"
}
}
}
}
}
stage('Build') {
agent { label 'linux-slave' }
steps {
configure()
buildProject()
addReleaseChannels()
}
}
stage('Deploy') {
agent { label 'linux-slave' }
when { anyOf { branch 'develop' ; branch 'master' } }
steps {
deployToS3()
deployToNPM()
}
}
}
}
def configure() {
def config = readJSON file: './services.config.json'
def manifest = readJSON file: './package.json'
GIT_SHORT_SHA = GIT_COMMIT.substring(0, 7)
PKG_VERSION = manifest.version
SERVICE_NAME = config.NAME
if (env.BRANCH_NAME == 'master') {
BUILD_VERSION = PKG_VERSION
CHANNEL = 'stable'
MANIFEST_NAME = 'app.json'
} else {
BUILD_VERSION = PKG_VERSION + '-alpha.' + env.BUILD_NUMBER
CHANNEL = 'staging'
MANIFEST_NAME = 'app.staging.json'
}
DIR_BUILD_ROOT = env.DSERVICE_S3_ROOT + SERVICE_NAME + '/'
DIR_BUILD_VERSION = DIR_BUILD_ROOT + BUILD_VERSION
DIR_DOCS_ROOT = env.DSERVICE_S3_ROOT_DOCS + SERVICE_NAME + '/'
DIR_DOCS_CHANNEL = DIR_DOCS_ROOT + CHANNEL
DIR_DOCS_VERSION = DIR_DOCS_ROOT + BUILD_VERSION
}
def buildProject() {
sh "npm install"
sh "npm run clean"
sh "VERSION=${BUILD_VERSION} npm run build"
sh "echo ${GIT_SHORT_SHA} > ./dist/SHA.txt"
sh "npm run zip"
sh "npm install [email protected] [email protected] --no-save"
sh "npm run docs"
}
def addReleaseChannels() {
if (env.BRANCH_NAME == 'master') {
sh "npm run channels"
}
}
def deployToS3() {
sh "aws s3 cp ./res/provider ${DIR_BUILD_VERSION}/ --recursive"
sh "aws s3 cp ./dist/provider ${DIR_BUILD_VERSION}/ --recursive"
sh "aws s3 cp ./dist/client/openfin-${SERVICE_NAME}.js ${DIR_BUILD_VERSION}/"
sh "aws s3 cp ./dist/docs ${DIR_DOCS_CHANNEL} --recursive"
sh "aws s3 cp ./dist/docs ${DIR_DOCS_VERSION} --recursive"
sh "aws s3 cp ./dist/provider/app.json ${DIR_BUILD_ROOT}${MANIFEST_NAME}"
sh "aws s3 cp ./dist/provider/ ${DIR_BUILD_ROOT} --recursive --exclude \"*\" --include \"app.runtime-*.json\""
}
def deployToNPM() {
if (env.DEPLOY_CLIENT != 'No') {
withCredentials([string(credentialsId: 'NPM_TOKEN_WRITE', variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > $WORKSPACE/.npmrc"
}
if (BUILD_VERSION == PKG_VERSION) {
// Assume production release
echo "publishing to npm, version: ${BUILD_VERSION}"
sh "npm publish"
} else {
// Assume staging release, and tag as 'alpha'
echo "publishing pre-release version to npm: ${BUILD_VERSION}"
sh "npm version --no-git-tag-version ${BUILD_VERSION}"
sh "npm publish --tag alpha"
sh "npm version --no-git-tag-version ${PKG_VERSION}"
}
}
}