-
Notifications
You must be signed in to change notification settings - Fork 78
/
Jenkinsfile
87 lines (85 loc) · 2.92 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pipeline {
agent any
environment {
DOCKERHUB_USERNAME = "kunchalavikram"
APP_NAME = "gitops-demo-app"
IMAGE_TAG = "${BUILD_NUMBER}"
IMAGE_NAME = "${DOCKERHUB_USERNAME}" + "/" + "${APP_NAME}"
REGISTRY_CREDS = 'dockerhub'
}
stages {
stage('Cleanup Workspace'){
steps {
script {
cleanWs()
}
}
}
stage('Checkout SCM'){
steps {
git credentialsId: 'github',
url: 'https://github.com/kunchalavikram1427/gitops-demo.git',
branch: 'dev'
}
}
stage('Build Docker Image'){
steps {
script{
docker_image = docker.build "${IMAGE_NAME}"
}
}
}
stage('Push Docker Image'){
steps {
script{
docker.withRegistry('', REGISTRY_CREDS ){
docker_image.push("${BUILD_NUMBER}")
docker_image.push('latest')
}
}
}
}
stage('Delete Docker Images'){
steps {
sh "docker rmi ${IMAGE_NAME}:${IMAGE_TAG}"
sh "docker rmi ${IMAGE_NAME}:latest"
}
}
stage('Updating Kubernetes deployment file'){
steps {
sh "cat deployment.yml"
sh "sed -i 's/${APP_NAME}.*/${APP_NAME}:${IMAGE_TAG}/g' deployment.yml"
sh "cat deployment.yml"
}
}
stage('Push the changed deployment file to Git'){
steps {
script{
sh """
git config --global user.name "vikram"
git config --global user.email "[email protected]"
git add deployment.yml
git commit -m 'Updated the deployment file' """
withCredentials([usernamePassword(credentialsId: 'github', passwordVariable: 'pass', usernameVariable: 'user')]) {
sh "git push http://$user:[email protected]/kunchalavikram1427/gitops-demo.git dev"
}
}
}
}
}
}
// stage('Build Docker Image'){
// steps {
// sh "docker build -t ${IMAGE_NAME}:${IMAGE_TAG} ."
// sh "docker build -t ${IMAGE_NAME}:latest ."
// }
// }
// stage('Push Docker Image'){
// steps {
// withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'pass', usernameVariable: 'user')]) {
// sh "docker login -u $user --password $pass"
// sh "docker push ${IMAGE_NAME}:${IMAGE_TAG} ."
// sh "docker push ${IMAGE_NAME}:latest ."
// }
// }
// }