-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathJenkinsfile
116 lines (111 loc) · 4.83 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
pipeline {
agent {
label 'mesos'
}
tools {
nodejs 'Node18'
}
environment {
BRANCH_NAME = sh(returnStdout: true, script: 'echo $GIT_BRANCH | sed "s#origin/##g"').trim()
GIT_COMMIT_MESSAGE = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
GIT_COMMIT_HASH = GIT_COMMIT.take(7)
}
stages {
stage('Setup') {
steps {
checkout scm
sh '''
echo $GIT_COMMIT_MESSAGE
node -v
npm -v
npm i --reg $REGISTRY -g @paypalcorp/web
'''
}
}
// For release, deploy existing build assets
stage('Bundle Stage') {
steps {
script {
if (GIT_COMMIT_MESSAGE.contains('chore(release)')) {
// include only version number section of commit message
env.VERSION=GIT_COMMIT_MESSAGE.substring(GIT_COMMIT_MESSAGE.indexOf(':') + 1, GIT_COMMIT_MESSAGE.indexOf('['))
// Stage tags can only contain alphnumeric characters and underscores
env.VERSION=VERSION.replace('.', '_').trim();
env.stageBundleId='up_stage_v' + VERSION + '_' + GIT_COMMIT_HASH
withCredentials([usernamePassword(credentialsId: 'web-cli-creds', passwordVariable: 'SVC_ACC_PASSWORD', usernameVariable: 'SVC_ACC_USERNAME')]) {
sh '''
rm -rf ./dist/bizcomponents/sandbox
rm -rf ./dist/bizcomponents/js
output=$(web stage --tag $stageBundleId)
web notify "$stageBundleId"
git checkout -- dist
'''
}
}
}
}
}
stage('Bundle Sandbox') {
steps {
script {
if (GIT_COMMIT_MESSAGE.contains('chore(release)')) {
env.sandboxBundleId='up_sb_v' + VERSION + '_' + GIT_COMMIT_HASH
withCredentials([usernamePassword(credentialsId: 'web-cli-creds', passwordVariable: 'SVC_ACC_PASSWORD', usernameVariable: 'SVC_ACC_USERNAME')]) {
sh '''
rm -rf ./dist/bizcomponents/stage
rm -rf ./dist/bizcomponents/js
output=$(web stage --tag $sandboxBundleId)
web notify "$sandboxBundleId"
git checkout -- dist
'''
}
}
}
}
}
stage('Build Production') {
steps {
script {
if (GIT_COMMIT_MESSAGE.contains('chore(release)')) {
env.productionBundleId='up_prod_v' + VERSION + '_' + GIT_COMMIT_HASH
withCredentials([usernamePassword(credentialsId: 'web-cli-creds', passwordVariable: 'SVC_ACC_PASSWORD', usernameVariable: 'SVC_ACC_USERNAME')]) {
sh '''
rm -rf ./dist/bizcomponents/stage
rm -rf ./dist/bizcomponents/sandbox
output=$(web stage --tag $productionBundleId)
web notify "$productionBundleId"
git checkout -- dist
'''
}
}
}
}
}
}
// Send email notification
post {
success {
emailext(
mimeType: 'text/html',
// Single quotes on this so the variable makes it to the email plugin instead of Jenkins trying to replace
to: '$DEFAULT_RECIPIENTS',
subject: "paypal-messaging-components - ${BRANCH_NAME} - Build #${env.BUILD_NUMBER} - SUCCESS!",
body: """
Build Succeeded!<br />
<br />
${GIT_COMMIT_MESSAGE}<br />
Build URL: ${BUILD_URL}<br />
<br />
Version ${env.VERSION} assets have been bundled and are ready for review.<br />
Please approve and deploy: <br />
1. Stage: ${BUNDLE_URL}${stageBundleId} <br />
2. Sandbox: ${BUNDLE_URL}${sandboxBundleId} <br />
3. Production: ${BUNDLE_URL}${productionBundleId} <br />
<br />
Regards,<br />
Your friendly neighborhood digital butler
"""
)
}
}
}