-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
65 lines (54 loc) · 2.24 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
#!groovy
def ZIP_FILE_NAME = "dist"
def SOURCE_CODE_BUCKET_NAME = "safe-step-lambda-functions-source"
def S3_OBJECT_KEY = "add-responsibility.zip"
def CF_STACK_NAME = "add-responsibility"
def CF_TEMPLATE_FILE_NAME = "template.json"
def String OBJECT_VERSION
pipeline {
agent any
tools {nodejs "nodejs"}
stages {
stage("Build") {
steps {
fileOperations([folderCreateOperation("dist")])
fileOperations([fileCopyOperation(excludes: "", flattenFiles: false, includes: "package.json", targetLocation: "dist")])
sh "npm install"
sh "tsc -b" // typescript transpile
dir ("dist") {
sh "npm install --only=prod" // install production libraries
}
fileOperations([ fileZipOperation(folderPath: ZIP_FILE_NAME, outputFolderPath: "./")]) // zip the result
}
}
stage("Test") {
steps {
sh "npm install" // install local including test packages
sh "npm run test-unit"
}
}
stage("Deploy") {
steps {
script {
OBJECT_VERSION = sh (
script: "aws s3api put-object --bucket ${SOURCE_CODE_BUCKET_NAME} --key ${S3_OBJECT_KEY} --body ${ZIP_FILE_NAME}.zip",
returnStdout: true
).trim().replaceAll("\\s","").split("\"")[2] // just extract the version
}
echo "S3 Object Version: ${OBJECT_VERSION}";
script {
jsonfile = readJSON(text: readFile(CF_TEMPLATE_FILE_NAME).trim())
jsonfile["Resources"]["AddResponsibilityLambda"]["Properties"]["Code"]["S3ObjectVersion"] = OBJECT_VERSION
writeJSON file: CF_TEMPLATE_FILE_NAME, json: jsonfile
echo "Injected S3 object version into template"
}
sh "aws cloudformation deploy --template-file ${CF_TEMPLATE_FILE_NAME} --stack-name ${CF_STACK_NAME} --capabilities CAPABILITY_NAMED_IAM"
}
}
}
post {
cleanup {
cleanWs()
}
}
}