-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile
67 lines (62 loc) · 1.99 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
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS = credentials('eb9c1cbf-8638-4a36-b866-dd6beb6471b0')
BACKEND_IMAGE = 'sidharthsingh7/rusty_backend'
DOCKER_TAG = 'latest'
DEPLOY_URL = 'http://ec2-3-7-69-234.ap-south-1.compute.amazonaws.com:3002/webhook'
}
stages {
stage('Build') {
steps {
script {
try {
echo 'Building the Docker image...'
sh "docker build -t ${BACKEND_IMAGE}:${DOCKER_TAG} ."
} catch (Exception e) {
error "Docker build failed: ${e.message}"
}
}
}
}
stage('Push') {
steps {
script {
try {
echo 'Pushing Docker image to DockerHub...'
docker.withRegistry('https://index.docker.io/v1/', DOCKERHUB_CREDENTIALS) {
def backendImage = docker.image("${BACKEND_IMAGE}:${DOCKER_TAG}")
backendImage.push()
}
} catch (Exception e) {
error "Docker push failed: ${e.message}"
}
}
}
}
stage('Deploy') {
steps {
script {
try {
echo 'Triggering deployment...'
sh "curl -X POST '${DEPLOY_URL}'"
} catch (Exception e) {
error "Deployment failed: ${e.message}"
}
}
}
}
}
post {
success {
echo 'Pipeline executed successfully!'
}
failure {
echo 'Pipeline execution failed. Please check the logs for details.'
}
always {
echo 'Cleaning up...'
sh 'docker system prune -f'
}
}
}