Skip to content

Commit

Permalink
Merge pull request #8 from rishyym0927/issue7
Browse files Browse the repository at this point in the history
Update Jenkinsfile Fixes #7
  • Loading branch information
Sidharth-Singh10 authored Oct 2, 2024
2 parents e6a74db + 2818496 commit 3374b61
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,63 @@ pipeline {
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 {
// Build the backend Docker image
sh 'docker build -t $BACKEND_IMAGE:$DOCKER_TAG .'
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 {
docker.withRegistry('https://index.docker.io/v1/', 'eb9c1cbf-8638-4a36-b866-dd6beb6471b0') {
def backendImage = docker.image("$BACKEND_IMAGE:$DOCKER_TAG")
backendImage.push()
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')
{

stage('Deploy') {
steps {
script {
sh 'curl -X POST "http://ec2-3-7-69-234.ap-south-1.compute.amazonaws.com:3002/webhook"'
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'
}
}
}

0 comments on commit 3374b61

Please sign in to comment.