-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
54 lines (46 loc) · 1.72 KB
/
Jenkinsfile
File metadata and controls
54 lines (46 loc) · 1.72 KB
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
pipeline {
environment {
DOCKERHUB_REGISTRY="https://hub.docker.com"
DOCKERHUB_CREDENTIALS="DOCKERHUB_CREDENTIALS"
REGION="us-east-1"
AWS_CREDENTIALS="aws_credentials"
}
agent any
stages {
stage('Lint HTML and Dockerfile') {
steps {
sh 'make lint'
}
}
stage('Build Docker and Push Image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: "${DOCKERHUB_CREDENTIALS}", usernameVariable: "DOCKERHUB_USERNAME", passwordVariable: "DOCKERHUB_PASSWORD")]) {
sh "echo $DOCKERHUB_PASSWORD >> dockerhub_password_file"
sh "cat dockerhub_password_file | docker login -u $DOCKERHUB_USERNAME --password-stdin"
sh "rm -rf dockerhub_password_file"
docker.withRegistry('', "$DOCKERHUB_CREDENTIALS") {
sh "make build"
sh "make upload"
}
}
}
}
}
stage('Deploy to Kubernetes Cluster') {
steps {
withAWS(credentials: "$AWS_CREDENTIALS", region: "$REGION") {
sh "aws eks --region us-east-1 update-kubeconfig --name devops-cluster"
sh "kubectl apply -f blue-deployment.yml"
sh "kubectl apply -f green-deployment.yml"
sh "kubectl apply -f service.yml"
}
}
}
stage('Remove Docker resources') {
steps {
sh "make clean"
}
}
}
}