-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
72 lines (72 loc) · 2.5 KB
/
Jenkinsfile
File metadata and controls
72 lines (72 loc) · 2.5 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pipeline {
agent any
environment {
// Define your Docker Hub credentials and image name here
DOCKER_IMAGE = 'redheaven/hello-world:latest' // Image name
KUBE_CONTEXT = 'your-kube-context' // Kube context if you have multiple clusters
KUBERNETES_NAMESPACE = 'testapp-yudi' // Replace with your namespace
}
stages {
stage('Checkout') {
steps {
// Checkout your repository
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'git', url: 'git@github.com:bahdik/minibdk.git']])
}
}
stage('Build Docker Image') {
steps {
script {
// Build Docker image
sh '''
docker build -t $DOCKER_IMAGE .
'''
}
}
}
stage('Docker Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhubcredentials', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
sh 'docker push $DOCKER_IMAGE'
}
}
}
// stage('delete manifest in Kubernetes') {
// steps {
// script {
// // Deploy to Kubernetes using kubectl
// sh '''
// kubectl delete -f k8s/deployment.yaml -n $KUBERNETES_NAMESPACE
// sleep 60
// '''
// }
// }
// }
stage('Deploy again to Kubernetes') {
steps {
script {
// Deploy to Kubernetes using kubectl
sh '''
kubectl apply -f k8s/deployment.yaml -n $KUBERNETES_NAMESPACE
'''
}
}
}
stage('rollout restart Kubernetes') {
steps {
script {
// Deploy to Kubernetes using kubectl
sh '''
kubectl rollout restart deployment/helloworld-app -n $KUBERNETES_NAMESPACE
'''
}
}
}
}
post {
always {
// Clean up if necessary, for example, remove the Docker image locally
sh 'docker rmi $DOCKER_IMAGE'
}
}
}