-
Notifications
You must be signed in to change notification settings - Fork 5
/
jenkinsfile
104 lines (94 loc) · 2.56 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// pipeline {
// agent any
// tools {nodejs "node 14"}
// // environment {
// // DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials')
// // }
// stages {
// stage('Checkout') {
// steps {
// checkout scm
// }
// }
// stage('Build and Start Services') {
// steps {
// dir('all_in_docker') {
// script {
// sh 'docker-compose build'
// sh 'docker-compose up -d'
// }
// }
// }
// }
// stage('Install Dependencies') {
// steps {
// dir('all_in_docker/client') {
// script {
// sh 'npm install'
// }
// }
// }
// }
// stage('Build') {
// steps {
// dir('all_in_docker/client') {
// script {
// sh 'CI=false npm run build'
// }
// }
// }
// }
// }
// post {
// always {
// cleanWs()
// }
// success {
// echo 'Pipeline succeeded!'
// }
// failure {
// echo 'Pipeline failed!'
// }
// }
// }
pipeline {
agent any
tools {dockerTool "docker"}
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials') // Jenkins credentials ID for Docker Hub
DOCKERHUB_REPO = 'samil88/frontend'
DOCKER_IMAGE_TAG = 'latest'
}
stages {
stage('Clone Repository') {
steps {
// Clone your repository
checkout scm
}
}
stage('Build Docker Image') {
steps {
dir('all_in_docker/client') {
script {
dockerImage = docker.build("${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG}")
}
}
}
}
stage('Push Docker Image') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials') {
dockerImage.push()
}
}
}
}
}
post {
always {
// Clean up Docker images to free up space
sh "docker rmi ${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG} || true"
}
}
}