-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
72 lines (67 loc) · 2.26 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
69
70
71
72
pipeline {
environment {
dockerhubCredentials = 'dockerhubCredentials'
}
agent any
stages {
stage('Build and Push') {
steps {
script{
echo 'Building'
sh 'docker build -t vprocopan/capstone-vprocopan .'
docker.withRegistry( '', dockerhubCredentials ) {
sh 'docker push vprocopan/capstone-vprocopan'
}
sh '''docker run --name capstone -d -p 80:80 vprocopan/capstone-vprocopan'''
}
}
}
stage('Test') {
steps {
script {
sh 'hadolint ./Dockerfile | tee ./hadolint_lint.txt'
sh '''
lintErrors=$(stat --printf="%s" ./hadolint_lint.txt)
if [ "$lintErrors" -gt "0" ]; then
echo "Errors have been found, please see below"
cat ./hadolint_lint.txt
exit 1
else
echo "There are no erros found on Dockerfile!!"
fi
'''
}
echo 'Testing..'
}
}
stage('Deploy to EKS') {
steps {
dir('k8s')
{
withAWS(credentials: 'aws-credentials', region: 'us-west-2')
{
sh "aws eks update-kubeconfig --name capstone --region us-west-2"
sh "kubectl run project --image=vprocopan/capstone-vprocopan --port=80"
}
}
echo 'Deploying....'
}
}
//stage("Cleaning Docker up") {
// steps {
// script {
//
// }
// }
// }
}
post {
always {
script {
sh "echo 'Cleaning Docker up'"
sh "docker rm -f capstone"
sh "echo > hadolint_lint.txt"
}
}
}
}