-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
54 lines (51 loc) · 1.75 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
pipeline {
agent any
stages {
/*
stage('Code Checkout') {
steps {
//This step is performed by Jenkins
git "https://github.com/mattocodes/capstone-jenkins-cicd"
}
}
*/
stage('Test Code') {
steps {
echo "Testing code..."
sh "tidy -q -e *.html"
}
}
stage('Build Code') {
steps {
echo "Building code..."
sh "docker build . -t mattocodes/testapp:${BUILD_NUMBER}"
sh "docker tag mattocodes/testapp:${BUILD_NUMBER} mattocodes/testapp:latest"
}
}
stage('Push Build to DockerHub') {
steps {
echo "Pushing build to DockerHub..."
withCredentials([string(credentialsId: 'dockerhub_id', variable: 'dockerhub_pwd')]) {
sh "docker login -u mattocodes -p ${dockerhub_pwd}"
sh "docker push mattocodes/testapp:${BUILD_NUMBER}"
sh "docker push mattocodes/testapp:latest"
}
}
}
stage('Deploy to Kubernetes') {
steps {
sshagent(['kubemasternode_id']) {
echo "Copying game-app file"
sh "scp -o StrictHostKeyChecking=no game-app.yml ubuntu@3.215.23.226:/home/ubuntu/"
script {
try {
sh "ssh ubuntu@3.215.23.226 kubectl apply -f ."
}catch(error) {
sh "ssh ubuntu@3.215.23.226 kubectl create -f ."
}
}
}
}
}
}
}