From f32bf41e37d017fea74ce2f533ae4bb0d0339841 Mon Sep 17 00:00:00 2001 From: Samil Date: Thu, 4 Jul 2024 09:11:11 +0545 Subject: [PATCH] cas --- jenkinsfile | 103 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 29 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 5619f47..c1b885d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -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" } } }