Skip to content

Commit

Permalink
cas
Browse files Browse the repository at this point in the history
  • Loading branch information
sshresthadh committed Jul 4, 2024
1 parent 849e63c commit f32bf41
Showing 1 changed file with 74 additions and 29 deletions.
103 changes: 74 additions & 29 deletions jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,102 @@
// 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 {nodejs "node 14"}

// environment {
// DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials')
// }
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials') // Jenkins credentials ID for Docker Hub
DOCKERHUB_REPO = 'samil88/frontend'
DOCKER_IMAGE_TAG = 'latest'
}

stages {
stage('Checkout') {
stage('Clone Repository') {
steps {
// Clone your repository
checkout scm
}
}
stage('Build and Start Services') {

stage('Build Docker Image') {
steps {
dir('all_in_docker') {
script {
sh 'docker-compose build'
sh 'docker-compose up -d'
dockerImage = docker.build("${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG}")
}
}
}
}
stage('Install Dependencies') {

stage('Push Docker Image') {
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'
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials') {
dockerImage.push()
}
}
}
}
}

post {
always {
cleanWs()
}
success {
echo 'Pipeline succeeded!'
}
failure {
echo 'Pipeline failed!'
// Clean up Docker images to free up space
sh "docker rmi ${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG} || true"
}
}
}

0 comments on commit f32bf41

Please sign in to comment.