forked from paypal/paypal-messaging-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
89 lines (83 loc) · 3.23 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
pipeline {
agent {
label 'mesos'
}
tools {
nodejs 'Node12'
}
// STAGE_TAG will be {branch_name}_{timestamp}
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()
// sed commands in order:
// remove origin/ from the branch name
// replace any hyphens (-) with underscores (_)
// shorten to 18 characters to allow space for the timestamp at the end
STAGE_TAG = sh(returnStdout: true, script: 'echo $(echo $GIT_BRANCH | sed "s#origin/##g" | sed "s/-/_/g" | sed -e "s/(.{18}).*/$1/g")_$(date +%s)').trim()
}
stages {
stage('Setup') {
steps {
checkout scm
sh '''
echo $GIT_COMMIT_MESSAGE
node -v
npm -v
npm set registry https://npm.paypal.com
npm i -g @paypalcorp/web
'''
}
}
// For non-release, auto-generate a stage build
stage('Stage Tag') {
when {
not {
branch 'release'
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'web-cli-creds', passwordVariable: 'SVC_ACC_PASSWORD', usernameVariable: 'SVC_ACC_USERNAME')]) {
sh 'npm run build -- -t $STAGE_TAG -s $TEST_ENV'
}
}
}
// For release, stage existing build assets and send notification
stage('Deploy') {
when {
branch 'release'
}
steps {
withCredentials([usernamePassword(credentialsId: 'web-cli-creds', passwordVariable: 'SVC_ACC_PASSWORD', usernameVariable: 'SVC_ACC_USERNAME')]) {
sh '''
OUTPUT=$(web stage --json --tag $STAGE_TAG)
web notify $STAGE_TAG
'''
}
}
}
}
// 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!",
// The ${FILE} similarly needs to be sent to the plugin to be replaced, so the $ is escaped
body: """
Build Succeeded!<br />
<br />
${GIT_COMMIT_MESSAGE}<br />
Build URL: ${env.BUILD_URL}<br />
Stage Tag: ${STAGE_TAG}<br />
CDN Bundle: https://UIDeploy--StaticContent--${STAGE_TAG}--ghe.preview.dev.paypalinc.com/upstream/bizcomponents/stage?cdn:list<br />
Test Page: ${TEST_URL}${STAGE_TAG}<br />
<br />
Regards,<br />
Your friendly neighborhood digital butler
"""
)
}
}
}