-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
77 lines (68 loc) · 2.02 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
/**
* CREDENTIALS:
* - ADD Jenkins global credentials -> add PRIV_AWS_ACCESS (aws key / assigned to admin user)
* - ADD ssh key for Jenkins user (jenkins / github)
* CREATE FOLDER (name of folder will be used as an environment eg dev/test/prod)
* - inside FOLDER create pipeline project that will points to this Jenkinsfile
*/
def functions
pipeline {
agent any
options {
timeout(time: 15, unit: "MINUTES")
withAWS(region: "${params.AWS_REGION}")
withCredentials([[$class : "AmazonWebServicesCredentialsBinding",
credentialsId : "${params.CREDENTIAL_ID}",
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']])
}
parameters {
choice(name: 'CREDENTIAL_ID', choices: 'PRIV_AWS_ACCESS', description: 'Supply name of AWS_KEY (Stored on Jenkins)')
choice(name: 'AWS_REGION', choices: 'eu-west-1\neu-west-2', description: 'Pick up region where app should be deployed (Ireland / London)')
}
stages {
stage('Load functions') {
steps {
script {
functions = load(pwd() + '/build/functions.groovy')
}
}
}
stage('Setup s3 deployment bucket') {
steps {
script {
functions.validateTemplates()
functions.updateDeploymentBucket()
functions.uploadTemplates()
}
}
}
stage('Test and build deployment package') {
steps {
script {
// clean up old dist files
sh 'rm -fr dist/*'
sh 'node -v'
sh 'npm run build'
sh 'npm prune --production'
sh 'zip -q -r dist/lambda.zip node_modules dist'
}
}
}
stage('Copy deployment package to S3 and update lambda') {
steps {
script {
functions.uploadLambdaCode()
functions.updateLambda()
}
}
}
stage('Test deployed lambda') {
steps {
script {
functions.callAWSLambda()
}
}
}
}
}