forked from buildit/devops-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
81 lines (70 loc) · 2.58 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
pipeline {
environment {
AWS_DEFAULT_REGION = 'eu-west-1'
AWS_PROFILE = "default"
}
agent any
stages {
stage("Gather Parameters") {
steps {
script {
operation = input message: 'Please provide parameters', ok: 'Deploy',
parameters: [
choice(name: 'Operation', choices: ['launch', 'delete'], description: 'What sceptre operation?')
]
}
}
}
stage ('Prep') {
steps {
script {
// sanitise the branch name, we'll use it for resource naming
branch = GIT_BRANCH.replaceAll("[^A-Za-z0-9]", "")
}
}
}
stage ('Tests') {
steps {
script {
sh "sceptre --var branch=${branch} --var asset=test.zip validate dev"
dir("src"){
sh "npm test"
}
}
}
}
stage("Deploy Prerequisites") {
steps {
script {
sh "sceptre --var branch=${branch} --var asset=test.zip ${operation} dev/prerequisites -y"
assets_bucket = sh(script:"eval \$(sceptre --var branch=master --ignore-dependencies list outputs dev/prerequisites.yaml --export=envvar) && echo \$SCEPTRE_AssetsBucket", returnStdout: true).trim()
}
}
}
stage("Package App") {
steps {
script {
if (operation == 'launch') {
long timestamp = System.currentTimeMillis() / 1000;
file_name = "test-app-" + timestamp + ".zip"
dir("src"){
sh 'npm ci'
sh "zip -r ../${file_name} *"
}
echo "package src dir to ${assets_bucket}"
sh "aws s3 cp ${file_name} s3://${assets_bucket}"
}
}
}
}
stage("Deploy App") {
steps {
script {
echo "placeholder"
sh "sceptre --var branch=${branch} --var asset=${file_name} ${operation} dev/app -y"
sh "sceptre --output json --var branch=${branch} --var asset=${file_name} --ignore-dependencies list outputs dev/app.yaml"
}
}
}
}
}