-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
68 lines (68 loc) · 3.06 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
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '15'))
}
environment {
WHOAMI = sh(returnStdout: true, script: 'echo -n `id -u`:`id -g`')
}
stages {
stage ('Initialize') {
agent {
docker {
image 'alpine'
reuseNode true
args '-u root -v mvn_repo:/tmp/.m2'
}
}
steps {
sh "chown -R ${WHOAMI} /tmp/.m2"
}
}
stage('Build') {
agent {
docker {
image 'maven:3.5.3-jdk-8-alpine'
reuseNode true
args '-v mvn_repo:/tmp/.m2 -e MAVEN_CONFIG=/tmp/.m2'
}
}
steps {
sh '''
mvn package
'''
}
}
stage('Deploy') {
agent {
docker {
image 'grolland/aws-cli'
reuseNode true
}
}
environment {
AWS_DEFAULT_REGION = 'eu-central-1'
AWS_ACCESS_KEY_ID = credentials('AWS_KEY_E2C_ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS_KEY_E2C_SECRET')
STACK_NAME = 'event2calendar'
S3_BUCKET = 'nc-projects-infrabucket'
}
steps {
s3Upload consoleLogLevel: 'INFO', dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'nc-infra-cfn-jenkins-artifacts', excludedFile: '', flatten: false, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: true, selectedRegion: 'eu-central-1', showDirectlyInBrowser: false, sourceFile: '**/target/*.jar', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'ARTIFACTS', userMetadata: []
sh '''
cd cfn
chmod +x prepare_template.sh
./prepare_template.sh
aws cloudformation package --template aws-resources.yml --s3-bucket $S3_BUCKET --s3-prefix event2calendar --output-template template-export.yml
aws cloudformation deploy --template-file=template-export.yml --stack-name="${STACK_NAME}" --capabilities=CAPABILITY_NAMED_IAM
'''
s3Upload consoleLogLevel: 'INFO', dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'nc-infra-cfn-jenkins-artifacts', excludedFile: '', flatten: false, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: true, selectedRegion: 'eu-central-1', showDirectlyInBrowser: false, sourceFile: 'cfn/template-export.yml', storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'ARTIFACTS', userMetadata: []
}
}
}
post {
always {
cleanWs()
}
}
}