Переглянути джерело

correction stage push and pull

DESKTOP-SMCIPAV\falko 5 місяців тому
батько
коміт
e3548781da
1 змінених файлів з 65 додано та 55 видалено
  1. 65 55
      Jenkinsfile

+ 65 - 55
Jenkinsfile

@@ -5,9 +5,7 @@ pipeline {
         NODEJS_HOME = "${tool 'NodeJS'}"
         PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"
 
-        DOCKER_REGISTRY = "nexus.foodgame.fr:8123"
-        IMAGE_NAME = "fatboar_repo/workflow_jenkins_1"
-        IMAGE_TAG = "latest"
+        
     }
 
     stages {
@@ -73,19 +71,19 @@ pipeline {
         //     }
         // }
 
-        stage('Build & Deploy') {
-            steps {
-                sh """
-                    docker-compose -f ${env.COMPOSE_FILE} build --no-cache
-                    docker-compose -f ${env.COMPOSE_FILE} up -d --force-recreate --remove-orphans
-                """
-                script {
-                    echo "Lancement du backup sur le container ${env.BACKUP_CONTAINER}"
-                    def backupCmd = "docker exec ${env.BACKUP_CONTAINER} /backup.sh || echo '⚠️ Backup ${env.ENV.toUpperCase()} échoué'"
-                    sh backupCmd
-                }
-            }
-        }
+        // stage('Build & Deploy') {
+        //     steps {
+        //         sh """
+        //             docker-compose -f ${env.COMPOSE_FILE} build --no-cache
+        //             docker-compose -f ${env.COMPOSE_FILE} up -d --force-recreate --remove-orphans
+        //         """
+        //         script {
+        //             echo "Lancement du backup sur le container ${env.BACKUP_CONTAINER}"
+        //             def backupCmd = "docker exec ${env.BACKUP_CONTAINER} /backup.sh || echo '⚠️ Backup ${env.ENV.toUpperCase()} échoué'"
+        //             sh backupCmd
+        //         }
+        //     }
+        // }
 
         stage('Push to Private Registry (Optional)') {
             when {
@@ -96,17 +94,29 @@ pipeline {
             }
             steps {
                 script {
-                    docker.withRegistry("https://${DOCKER_REGISTRY}", 'nexus') {
+                    def registryUrl = 'nexus.foodgame.fr:8123'
+                    def imageName = 'grafana/tns-db'
+                    def imageVersion = 'latest'
+                    
+                    docker.withRegistry("https://${registryUrl}", 'nexus') {
                         try {
-                            echo "Pull image from registry"
-                            docker.image("${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}").pull()
+                            Try pulling the image from the registry
+                            echo "Trying to pull image: ${registryUrl}/${imageName}:${imageVersion}"
+                            docker.image("${registryUrl}/${imageName}:${imageVersion}").pull()
                         } catch (Exception e) {
-                            echo "Build and push image"
-                            sh """
-                                docker pull ${IMAGE_NAME}:${IMAGE_TAG}
-                                docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
-                                docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
-                            """
+                            echo "Image pull failed. Attempting to build and push."
+
+                            Pull base image from Docker Hub
+                            echo "Pulling base image: ${imageName}:${imageVersion}"
+                            sh "docker pull ${imageName}:${imageVersion}"
+                            
+                            Tag the image for the private registry
+                            echo "Tagging image for private registry"
+                            sh "docker tag ${imageName}:${imageVersion} ${registryUrl}/${imageName}:${imageVersion}"
+                            
+                            Push the tagged image to the private registry
+                            echo "Pushing image to private registry"
+                            sh "docker push ${registryUrl}/${imageName}:${imageVersion}"
                         }
                     }
                 }
@@ -202,40 +212,40 @@ pipeline {
 //         //     }
 //         // }
     
-//         stage('Docker Registry Login, Pull, and Push') {
-//             when {
-//                 branch 'dev'
-//             }
-//             steps {
-//                 script {
-//                     def registryUrl = 'nexus.foodgame.fr:8123'
-//                     def imageName = 'grafana/tns-db'
-//                     def imageVersion = 'latest'
+        // stage('Docker Registry Login, Pull, and Push') {
+        //     when {
+        //         branch 'dev'
+        //     }
+        //     steps {
+        //         script {
+        //             def registryUrl = 'nexus.foodgame.fr:8123'
+        //             def imageName = 'grafana/tns-db'
+        //             def imageVersion = 'latest'
                     
-//                     docker.withRegistry("https://${registryUrl}", 'nexus') {
-//                         try {
-//                             Try pulling the image from the registry
-//                             echo "Trying to pull image: ${registryUrl}/${imageName}:${imageVersion}"
-//                             docker.image("${registryUrl}/${imageName}:${imageVersion}").pull()
-//                         } catch (Exception e) {
-//                             echo "Image pull failed. Attempting to build and push."
+        //             docker.withRegistry("https://${registryUrl}", 'nexus') {
+        //                 try {
+        //                     Try pulling the image from the registry
+        //                     echo "Trying to pull image: ${registryUrl}/${imageName}:${imageVersion}"
+        //                     docker.image("${registryUrl}/${imageName}:${imageVersion}").pull()
+        //                 } catch (Exception e) {
+        //                     echo "Image pull failed. Attempting to build and push."
 
-//                             Pull base image from Docker Hub
-//                             echo "Pulling base image: ${imageName}:${imageVersion}"
-//                             sh "docker pull ${imageName}:${imageVersion}"
+        //                     Pull base image from Docker Hub
+        //                     echo "Pulling base image: ${imageName}:${imageVersion}"
+        //                     sh "docker pull ${imageName}:${imageVersion}"
                             
-//                             Tag the image for the private registry
-//                             echo "Tagging image for private registry"
-//                             sh "docker tag ${imageName}:${imageVersion} ${registryUrl}/${imageName}:${imageVersion}"
+        //                     Tag the image for the private registry
+        //                     echo "Tagging image for private registry"
+        //                     sh "docker tag ${imageName}:${imageVersion} ${registryUrl}/${imageName}:${imageVersion}"
                             
-//                             Push the tagged image to the private registry
-//                             echo "Pushing image to private registry"
-//                             sh "docker push ${registryUrl}/${imageName}:${imageVersion}"
-//                         }
-//                     }
-//                 }
-//             }
-//         }
+        //                     Push the tagged image to the private registry
+        //                     echo "Pushing image to private registry"
+        //                     sh "docker push ${registryUrl}/${imageName}:${imageVersion}"
+        //                 }
+        //             }
+        //         }
+        //     }
+        // }