-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsFile
More file actions
78 lines (70 loc) · 1.98 KB
/
Copy pathJenkinsFile
File metadata and controls
78 lines (70 loc) · 1.98 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
pipeline {
agent any
environment {
DOCKER_IMAGE = 'your_dockerhub_username/your_project_name'
DOCKER_CREDENTIALS = 'dockerhub_credentials'
CONTAINER_NAME = 'your_container_name'
DEPLOY_SERVER = 'your_server_ip_or_hostname'
}
stages {
stage('Checkout') {
steps {
script {
echo 'Checking out the code from the repository...'
checkout scm
}
}
}
stage('Build') {
steps {
script {
echo 'Building the Docker image...'
docker.build(DOCKER_IMAGE)
}
}
}
stage('Push to Docker Hub') {
steps {
script {
echo 'Logging into Docker Hub and pushing the image...'
docker.withRegistry('', DOCKER_CREDENTIALS) {
docker.image(DOCKER_IMAGE).push('latest')
}
}
}
}
stage('Deploy') {
steps {
script {
echo 'Deploying the application...'
sh """
docker stop ${CONTAINER_NAME} || true
docker rm ${CONTAINER_NAME} || true
"""
sh """
docker run -d --name ${CONTAINER_NAME} -p 80:80 ${DOCKER_IMAGE}:latest
"""
echo 'Deployment successful!'
}
}
}
}
post {
always {
script {
echo 'Pipeline execution completed.'
cleanWs()
}
}
success {
script {
echo 'Pipeline executed successfully!'
}
}
failure {
script {
echo 'Pipeline failed! Check logs for details.'
}
}
}
}