formation 11 ヶ月 前
コミット
2d66aceb02
1 ファイル変更17 行追加8 行削除
  1. 17 8
      Jenkinsfile

+ 17 - 8
Jenkinsfile

@@ -89,23 +89,32 @@ pipeline {
         //     }
         // }
 
-      stage('Docker Registry Login, Pull, and Push') {
+     stage('Docker Registry Login, Pull, and Push') {
     when {
         branch 'master'
     }
     steps {
         script {
-            docker.withRegistry('https://nexus.foodgame.fr:8123', 'nexus') {
-                // Pull image
-                docker.image('nexus.foodgame.fr:8123/fatboar_master_express_preprod:latest').pull()
-                
-                // Push image
-                docker.image('nexus.foodgame.fr:8123/fatboar_master_express_preprod:latest').push()
+            def imageName = 'fatboar_master_express_preprod'
+            def registryUrl = 'nexus.foodgame.fr:8123'
+            
+            docker.withRegistry("https://${registryUrl}", 'nexus') {
+                try {
+                    docker.image("${registryUrl}/${imageName}:latest").pull()
+                } catch (Exception e) {
+                    echo "Image pull failed. Attempting to build and push."
+                    
+                    // Build image
+                    def customImage = docker.build("${imageName}")
+                    
+                    // Tag and push
+                    customImage.tag("${registryUrl}/${imageName}:latest")
+                    customImage.push()
+                }
             }
         }
     }
 }
-
         stage('Cleanup') {
             steps {
                 echo "Nettoyage terminé pour la branche ${env.BRANCH_NAME}"