-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkfile
43 lines (38 loc) · 1.09 KB
/
Jenkfile
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
pipeline {
agent any
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 {
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"
}
}
}