-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
70 lines (65 loc) · 3.21 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
#!groovy
if (env.BRANCH_NAME == "main") {
buildEnv = "production"
executorEnv = "prod"
} else {
buildEnv = "dev"
executorEnv = "dev"
}
node('executor') {
ws("/tmp/${env.JOB_NAME}/${env.BRANCH_NAME}") {
checkout scm
def authorName = sh(returnStdout: true, script: 'git --no-pager show --format="%an" --no-patch').trim()
stage("Build") {
try {
sh """#!/bin/bash -ex
. $HOME/.nvm/nvm.sh ; nvm use 18.17.1
node -v
npm -v
npm install
npm run build-${buildEnv}"""
stash includes: "**/dist/**", name: 'dist'
// stash includes: "**/web-components/build/**", name: 'buildComponents'
} catch (e) {
slackSend(color: '#b20000', message: "FAILED: Build! '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) by ${authorName}")
throw e
}
}
stage("Test") {
try {
sh """#!/bin/bash
. $HOME/.nvm/nvm.sh ; nvm use 18.17.1
xvfb-run --auto-servernum --server-args='-screen 0, 1024x768x16' npm test"""
} catch (e) {
slackSend(color: '#b20000', message: "FAILED: Tests! '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) by ${authorName}")
throw e
}
}
if (["main", "dev"].contains(env.BRANCH_NAME)) {
stage('Deploy') {
node("${executorEnv}-executor") {
def bucketName = "pennsieve-${executorEnv}-app-use1"
try {
unstash 'dist'
sh "aws s3 --region us-east-1 rm --recursive s3://$bucketName/"
sh "aws s3 --region us-east-1 cp --recursive dist s3://$bucketName"
sh "aws s3 --region us-east-1 cp --cache-control 0 dist/index.html s3://$bucketName/"
def distributionId = sh(
script: "aws cloudfront list-distributions --query \"DistributionList.Items[?contains(Origins.Items[0].DomainName, '${bucketName}.s3.amazonaws.com')].Id\" --output text",
returnStdout: true
).trim()
def response = sh(returnStdout: true, script: "aws cloudfront create-invalidation --distribution-id ${distributionId} --paths '/*'").trim()
println "$response"
def responseMap = new groovy.json.JsonSlurperClassic().parseText(response)
def invalidation = responseMap.Invalidation
sh "aws cloudfront wait invalidation-completed --distribution-id ${distributionId} --id ${invalidation.Id}"
} catch (e) {
slackSend(color: '#b20000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) by ${authorName}")
throw e
}
}
}
}
slackSend(color: '#006600', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) by ${authorName}")
}
}