-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
71 lines (61 loc) · 1.92 KB
/
Jenkinsfile
File metadata and controls
71 lines (61 loc) · 1.92 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
pipeline {
agent {
docker {
image 'docker:29.0-cli'
args '--privileged -v /var/run/docker.sock:/var/run/docker.sock --user root'
}
}
environment {
DOCKERHUB_USER = "mandperfect"
//DOCKER_PATH = "weather-app-python"
}
stages {
stage('Checkout Code from SCM') {
steps {
git branch: 'main',
url: 'https://github.com/mandperfect/weather-app-python.git'
}
}
stage('Build Docker Images') {
steps {
script {
services = ["alert-service", "gateway", "weather-service"]
for (service in services) {
sh """
docker build -t ${DOCKERHUB_USER}/${service}:latest ./${service}
"""
}
}
}
}
stage('Push Docker Images') {
steps {
withCredentials([usernamePassword(
credentialsId: 'dockerhub-cred',
usernameVariable: 'DOCKER_USER',
passwordVariable: 'PASS'
)]) {
sh """
echo $PASS | docker login -u $DOCKER_USER --password-stdin
"""
script {
services = ["alert-service", "gateway", "weather-service"]
for (service in services) {
sh """
docker push ${DOCKERHUB_USER}/${service}:latest
"""
}
}
}
}
}
}
post {
success {
echo "All images built and pushed successfully"
}
failure {
echo "Build Pipeline failed. Please check the logs for details."
}
}
}