-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathJenkinsfile.groovy
55 lines (39 loc) · 1.61 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
import groovy.json.JsonSlurperClassic
node {
env.AWS_DEFAULT_REGION = 'ap-southeast-1'
def applicationName = 'kustian' //change me
def deploymentGroupName = 'kustian' // change me
def s3BucketName = 'deployment-cdc'
//Cleanup workspace
deleteDir()
stage('Checkout') {
checkout scm
}
stage("Sonar Analyze") {
def scannerHome = tool 'default';
withSonarQubeEnv('default') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${deploymentGroupName} -Dsonar.sources=app"
}
}
stage('Deploy') {
withCredentials([[$class : 'UsernamePasswordMultiBinding',
credentialsId : 'CdcAWS',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY']]) {
//Zip artifact
def artifactName = "${applicationName}-${deploymentGroupName}"
sh("zip -r ${artifactName}.zip .")
//Upload artifact to S3
sh("aws s3 cp ${artifactName}.zip s3://${s3BucketName}/${artifactName}.zip")
//Create Deployment
def result = sh(returnStdout:true, script: "aws deploy create-deployment --application-name ${applicationName} --deployment-group-name ${deploymentGroupName} --s3-location bucket=${s3BucketName},bundleType=zip,key=${artifactName}.zip")
def json = parseJson(result)
String deploymentId = json.deploymentId
//Wait until success
sh("aws deploy wait deployment-successful --deployment-id ${deploymentId}")
}
}
}
def parseJson(String json) {
return new JsonSlurperClassic().parseText(json)
}