-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
49 lines (43 loc) · 2.11 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
pipeline {
agent any
parameters {
string(name: 'AWS_ACCOUNT_ID', defaultValue: '', description: 'AWS account id where ecs stack should be deployed')
string(name: 'AWS_REGION', defaultValue: 'eu-west-1', description: 'AWS region where ecs stack should be deployed')
string(name: 'S3_BUCKET_NAME', defaultValue: 'apidefs', description: 'AWS S3 bucket where API definition can be uploaded')
}
stages {
stage('Build application jar') {
steps {
sh "mvn clean package"
}
}
stage('Build docker image and push to AWS registry') {
steps {
withCredentials([aws(credentialsId: "aws_credentials")]) {
sh '''
aws ecr get-login-password --region ${params.AWS_REGION} | docker login --username AWS --password-stdin ${params.AWS_ACCOUNT_ID}.dkr.ecr.${params.AWS_REGION}.amazonaws.com
aws ecr create-repository --repository-name tuicodechallenge
docker build -t com.example/tuicodechallenge .
docker tag com.example/tuicodechallenge:latest ${params.AWS_ACCOUNT_ID}.dkr.ecr.${params.AWS_REGION}.amazonaws.com/tuicodechallenge
docker push ${params.AWS_ACCOUNT_ID}.dkr.ecr.${params.AWS_REGION}.amazonaws.com/tuicodechallenge
'''
}
}
}
stage('Upload API specification to S3') {
steps {
withCredentials([aws(credentialsId: "aws_credentials")]) {
sh "aws s3 cp api_spec.yaml s3://${params.S3_BUCKET_NAME}"
}
}
}
stage('Deploy application stack to AWS') {
steps {
withCredentials([aws(credentialsId: "aws_credentials")]) {
//TODO replace with SAM CLI - sam package + deploy
sh "aws cloudformation create-stack --stack-name tui-example-ecs-stack --template-body file://aws/samTemplate.yaml --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND"
}
}
}
}
}