-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.groovy
177 lines (148 loc) · 6.98 KB
/
Jenkinsfile.groovy
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env groovy
def slackChannel = "ltis-ltr"
def slackCredentials = "UoA-Slack-Access-ltis-ltr"
pipeline {
agent {
label("uoa-buildtools-ionic")
}
parameters {
choice(choices: ['DEV', 'TEST', 'PROD'], description: 'What environment?', name: 'DEPLOY_ENV')
gitParameter name: 'BRANCH', type: 'PT_BRANCH', defaultValue: 'master', description: 'What Git branch you want to checkout?'
}
stages {
stage("Checkout") {
steps {
echo "Checking out.."
checkout([$class: 'GitSCM',
branches: [[name: "${params.BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'lib-bitbucket-user', url: 'https://bitbucket.org/uoa/media-player-cloud-frontend.git']]
])
}
}
stage('AWS Credential Grab') {
steps{
script {
echo "☯ Authenticating with AWS"
def awsCredentialsId = ''
def awsTokenId = ''
def awsProfile = ''
if (params.DEPLOY_ENV == 'DEV') {
echo 'Setting variables for DEV deployment'
awsCredentialsId = 'aws-user-sandbox'
awsTokenId = 'aws-token-sandbox'
awsProfile = 'uoa-sandbox'
} else if (params.DEPLOY_ENV == 'TEST') {
echo 'Setting variables for TEST deployment'
awsCredentialsId = 'uoa-its-nonprod-access'
awsTokenId = 'uoa-its-nonprod-token'
awsProfile = 'uoa-its-nonprod'
} else if (params.DEPLOY_ENV == 'PROD') {
echo 'Setting variables for PROD deployment'
awsCredentialsId = 'uoa-its-prod-access'
awsTokenId = 'uoa-its-prod-token'
awsProfile = 'uoa-its-prod'
} else {
echo 'No Env set'
}
withCredentials([
usernamePassword(credentialsId: "${awsCredentialsId}", passwordVariable: 'awsPassword', usernameVariable: 'awsUsername'),
string(credentialsId: "${awsTokenId}", variable: 'awsToken')
]) {
sh "python3 /home/jenkins/aws_saml_login.py --idp iam.auckland.ac.nz --user $awsUsername --password $awsPassword --token $awsToken --profile ${awsProfile}"
}
}
}
}
stage("Build") {
steps {
script {
def ionicBuild = ''
sh "node --version"
sh "npm --version"
sh "ionic --version"
sh "npm install"
if (params.DEPLOY_ENV == 'DEV') {
echo 'Setting variables for DEV deployment'
ionicBuild = "sandbox"
} else if (params.DEPLOY_ENV == 'TEST') {
echo 'Setting variables for TEST deployment'
ionicBuild = "nonprod"
} else if (params.DEPLOY_ENV == 'PROD') {
echo 'Setting variables for PROD deployment'
ionicBuild = "production"
} else {
echo 'No Env set'
}
echo "Replacing Version Number in the app..."
sh "sed -i 's/VERSION_WILL_BE_REPLACED_BY_CICD/#${env.BUILD_NUMBER}/g' src/environments/environment.${ionicBuild}.ts"
echo "Building the app..."
sh "ionic build --configuration=${ionicBuild}"
echo "Build complete"
}
}
}
stage("Deploy to S3 bucket") {
steps {
script {
echo "Deploying..."
def awsProfile = ''
def s3BucketName = ''
if (params.DEPLOY_ENV == 'DEV') {
echo 'Setting variables for DEV deployment'
awsProfile = "uoa-sandbox"
s3BucketName = "uoa-mediaplayer-sandbox"
} else if (params.DEPLOY_ENV == 'TEST') {
echo 'Setting variables for TEST deployment'
awsProfile = "uoa-its-nonprod"
s3BucketName = "uoa-mediaplayer-nonprod"
} else if (params.DEPLOY_ENV == 'PROD') {
echo 'Setting variables for PROD deployment'
awsProfile = "uoa-its-prod"
s3BucketName = "uoa-mediaplayer"
} else {
echo 'No Env set'
}
sh "aws s3 sync www s3://${s3BucketName} --delete --profile ${awsProfile}"
echo "Sync complete"
}
}
}
stage("Invalidate CloudFront") {
steps {
script {
echo "Invalidating..."
def awsProfile = ''
def awsCloudFrontDistroId = ''
if (params.DEPLOY_ENV == 'DEV') {
echo 'Setting variables for DEV deployment'
awsProfile = "uoa-sandbox"
awsCloudFrontDistroId = 'E19H7B2G6KOA04'
} else if (params.DEPLOY_ENV == 'TEST') {
echo 'Setting variables for TEST deployment'
awsProfile = "uoa-its-nonprod"
awsCloudFrontDistroId = 'E1QUMW4UUMHEKM'
} else if (params.DEPLOY_ENV == 'PROD') {
echo 'Setting variables for PROD deployment'
awsProfile = "uoa-its-prod"
awsCloudFrontDistroId = 'E2BR0LHEEJUQ60'
} else {
echo 'No Env set'
}
sh "aws cloudfront create-invalidation --distribution-id ${awsCloudFrontDistroId} --paths '/*' --profile ${awsProfile}"
echo "Invalidation started"
}
}
}
stage("Notify Slack Channel") {
steps {
script{
slackSend(channel: slackChannel, message:"Media Player Cloud has been deployed to " + params.DEPLOY_ENV, tokenCredentialId: slackCredentials)
}
}
}
}
}