This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJenkinsfile
74 lines (72 loc) · 2.73 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
@Library(value='[email protected]', changelog=false) _
pipeline {
agent {
node {
label 'team:iow'
}
}
environment {
npm_config_cache = 'npm-cache'
HOME = '.'
}
parameters {
choice(choices: ['DEV', 'TEST', 'QA', 'PROD-EXTERNAL'], description: 'Deploy Stage (i.e. tier)', name: 'DEPLOY_STAGE')
}
triggers {
pollSCM('H/5 * * * *')
}
stages {
stage('Set build description') {
steps {
script {
currentBuild.description = "Deploy to ${env.DEPLOY_STAGE} tier"
}
}
}
stage('run build the zip file for lambda') {
agent {
dockerfile {
label 'team:iow'
}
}
steps {
script {
if ("${params.DEPLOY_STAGE}" == 'DEV') {
def secretsString = sh(script: '/usr/local/bin/aws ssm get-parameter --name "/aws/reference/secretsmanager/IOW_AWS" --query "Parameter.Value" --with-decryption --output text --region "us-west-2"', returnStdout: true).trim()
def secretsJson = readJSON text: secretsString
def iowDevAccountNumber = secretsJson.accountNumber
def devAccountRoleName = secretsJson.roleName
def assumeRoleName = "arn:aws:iam::$iowDevAccountNumber:role/$devAccountRoleName"
def assumeRoleResp = sh(script: "/usr/local/bin/aws sts assume-role --role-arn $assumeRoleName --role-session-name expt-session --duration-seconds 3600", returnStdout: true).trim()
def roleJson = readJSON text: assumeRoleResp
env.AWS_ACCESS_KEY_ID = roleJson.Credentials.AccessKeyId
env.AWS_SECRET_ACCESS_KEY = roleJson.Credentials.SecretAccessKey
env.AWS_SESSION_TOKEN = roleJson.Credentials.SessionToken
env.BUCKET = 'iow-cloud-applications-dev'
} else {
env.BUCKET = 'iow-cloud-applications'
}
}
sh '''
npm install
./node_modules/serverless/bin/serverless.js deploy --stage ${DEPLOY_STAGE} --bucket ${BUCKET} --region us-west-2
'''
}
}
}
post {
always {
script {
pipelineUtils.cleanWorkspace()
}
}
failure {
script {
pipelineUtils.sendEmailNotification(
to: '[email protected]',
attachLog: true
)
}
}
}
}