-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
64 lines (58 loc) · 1.85 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
pipeline {
agent any
environment {
AWS_ACCOUNT_ID = '905418225867'
AWS_REGION = 'us-east-2'
ECR_REPO_NAME = 'discord-clone'
ECS_CLUSTER_NAME = 'discord-clone'
ECS_SERVICE_NAME = 'discord-clone-service'
DOCKER_IMAGE = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO_NAME}:${env.BUILD_ID}"
DATABASE_URL = 'your-database-url'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build Docker Image') {
steps {
script {
withAWS(credentials: 'aws-ecr-credentials', region: "${AWS_REGION}") {
sh '''
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
docker build -t ${DOCKER_IMAGE} .
docker push ${DOCKER_IMAGE}
'''
}
}
}
}
stage('Run Tests') {
steps {
script {
docker.image("${DOCKER_IMAGE}").inside {
sh 'npm install'
sh 'npm run test'
}
}
}
}
stage('Deploy to ECS') {
steps {
script {
withAWS(credentials: 'aws-ecr-credentials', region: "${AWS_REGION}") {
sh '''
aws ecs update-service --cluster ${ECS_CLUSTER_NAME} --service ${ECS_SERVICE_NAME} --force-new-deployment
'''
}
}
}
}
}
post {
always {
cleanWs()
}
}
}