forked from lvthillo/python-flask-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
148 lines (125 loc) · 3.29 KB
/
Copy pathJenkinsfile
File metadata and controls
148 lines (125 loc) · 3.29 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
pipeline{
agent any
environment {
DOCKERHUB_CREDENTIALS=credentials('DockerHub')
// KUBECONFIG="/etc/rancher/rke2/rke3.yaml"
TAG = "alpha"
}
stages {
// stage('Skip Build') {
// steps {
// scmSkip(skipPattern:'.*\\[ci skip\\].*')
// }
// }
stage('Skip Build') {
steps {
script{
def result = sh (script: "git log -1 | grep '\\[ci skip\\]'", returnStatus: true)
if (result != 0) {
echo "performing build..."
} else {
currentBuild.result = 'ABORTED'
error('Stopping early…')
}
}
}
}
stage('Building Image') {
steps {
sh "docker build -t jibranhaseeb/python-flask-app:${TAG} ."
}
}
stage('Login to Docker Hub') {
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('Push Image') {
steps {
sh "docker push jibranhaseeb/python-flask-app:${TAG}"
}
}
stage("git pull"){
steps{
withCredentials([string(credentialsId: 'Git', variable: 'SECRET')]) {
sh("git pull https://${SECRET}@github.com/Jibran19983/python-flask-docker.git master --force")
sh "git checkout master"
}
}
}
stage("changing the tag in the file"){
steps{
sh "sed -i 's|newTag: .*|newTag: ${TAG}|' ./cluster/kustomization.yaml"
}
}
stage("pushing to git"){
steps{
script{
withCredentials([string(credentialsId: 'Git', variable: 'SECRET')]) {
sh "git branch --show-current"
sh ("git add -A")
sh ("git commit -m '[ci skip]'")
}
}
}
}
// stage('Deploy the image in kubernetes cluster') {
// steps{
// script{
// withKubeConfig([credentialsId: 'Kubernetes', serverUrl: 'https://127.0.0.1:6443']) {
// sh 'kubectl apply -f ./cluster/flask-app.yml'
// }
// }
// }
// }
// stage('Testing the Web app') {
// steps{
// script{
// withKubeConfig([credentialsId: 'Kubernetes', serverUrl: 'https://127.0.0.1:6443']) {
// sleep 10
// def ip = sh script: 'kubectl get service/my-flask-service -o jsonpath="{.spec.clusterIP}"', returnStdout: true
// ip = ip.trim()
// def result = sh script:"curl -s -o /dev/null -w '%{http_code}' ${ip}:8080", returnStdout: true
// if(result=="200"){
// echo "Pipeline Implemented Successfully"
// }
// else{
// error("Test Failed")
// }
// }
// }
// }
// }
}
post {
always {
sh 'docker logout'
script{
withCredentials([string(credentialsId: 'Git', variable: 'SECRET')]) {
sh("git push https://${SECRET}@github.com/Jibran19983/python-flask-docker.git master --force")
}
}
}
success{
script{
withCredentials([string(credentialsId: 'EmailAddress', variable: 'EMAIL')]) {
emailext body: 'Your pipeline is successfully built',
subject: 'Pipeline Successful',
to: EMAIL
}
}
}
failure{
script{
withCredentials([string(credentialsId: 'EmailAddress', variable: 'EMAIL')]) {
emailext body: 'Your pipeline failes',
subject: 'Pipeline Failed',
to: EMAIL
}
if (currentBuild.result == 'ABORTED'){
deleteDir()
}
}
}
}
}