Quellcode durchsuchen

Ajout du stage pull and push

DESKTOP-SMCIPAV\falko vor 5 Monaten
Ursprung
Commit
9b6b14cfe4
1 geänderte Dateien mit 40 neuen und 40 gelöschten Zeilen
  1. 40 40
      Jenkinsfile

+ 40 - 40
Jenkinsfile

@@ -8,42 +8,42 @@ pipeline {
         PROD_URL = "prod.foodgame.fr"
     }
     stages {
-        // ... (autres stages inchangés)
+        ... (autres stages inchangés)
 
-        // stage('Docker Registry Login, Pull, and Push') {
-        //     when {
-        //         branch 'dev'
-        //     }
-        //     steps {
-        //         script {
-        //             def registryUrl = 'nexus.foodgame.fr:8123'
-        //             def imageName = 'quay.io/prometheus/node-exporter'
-        //             def imageVersion = 'latest'
+        stage('Docker Registry Login, Pull, and Push') {
+            when {
+                branch 'dev'
+            }
+            steps {
+                script {
+                    def registryUrl = 'nexus.foodgame.fr:8123'
+                    def imageName = 'quay.io/prometheus/node-exporter'
+                    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}"
+                        }
+                    }
+                }
+            }
+        }
         stage('Stop Containers') {
             steps {
                 sh '''
@@ -70,15 +70,15 @@ pipeline {
             }
         }
          
-       stage('Build & Deploy') {
-           steps {
-            sh '''
-               docker-compose stop
-               docker-compose build --no-cache
-               docker-compose up -d --force-recreate --remove-orphans
-               '''
-  }
-}
+//        stage('Build & Deploy') {
+//            steps {
+//             sh '''
+//                docker-compose stop
+//                docker-compose build --no-cache
+//                docker-compose up -d --force-recreate --remove-orphans
+//                '''
+//   }
+// }
 
         // ... (autres stages inchangés)
     }