formation 11 月之前
父節點
當前提交
d26020ad98
共有 1 個文件被更改,包括 41 次插入40 次删除
  1. 41 40
      Jenkinsfile

+ 41 - 40
Jenkinsfile

@@ -33,22 +33,22 @@ pipeline {
             }
         }
 
-        stage('SonarQube Analysis') {
-            steps {
-                script {
-                    def scannerHome = tool name: 'SonarQube Scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
-                    withSonarQubeEnv('SonarQube') { // Nom du serveur SonarQube configuré dans Jenkins
-                        sh """
-                        ${scannerHome}/bin/sonar-scanner \
-                        -Dsonar.projectKey=FatboarProject-${env.BRANCH_NAME} \
-                        -Dsonar.sources=. \
-                        -Dsonar.host.url=https://sonarqube.foodgame.fr \
-                        -Dsonar.login=sqa_d81445ef2d3961cddf7e29e31c1aeb2505aacdbd
-                        """
-                    }
-                }
-            }
-        }
+        // stage('SonarQube Analysis') {
+        //     steps {
+        //         script {
+        //             def scannerHome = tool name: 'SonarQube Scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
+        //             withSonarQubeEnv('SonarQube') { // Nom du serveur SonarQube configuré dans Jenkins
+        //                 sh """
+        //                 ${scannerHome}/bin/sonar-scanner \
+        //                 -Dsonar.projectKey=FatboarProject-${env.BRANCH_NAME} \
+        //                 -Dsonar.sources=. \
+        //                 -Dsonar.host.url=https://sonarqube.foodgame.fr \
+        //                 -Dsonar.login=sqa_d81445ef2d3961cddf7e29e31c1aeb2505aacdbd
+        //                 """
+        //             }
+        //         }
+        //     }
+        // }
 
         stage('Stop Containers') {
             steps {
@@ -59,15 +59,15 @@ pipeline {
             }
         }
 
-        stage('Build & Deploy') {
-            steps {
-                sh '''
-                docker-compose stop
-                docker-compose build
-                docker-compose up -d
-                '''
-            }
-        }
+        // stage('Build & Deploy') {
+        //     steps {
+        //         sh '''
+        //         docker-compose stop
+        //         docker-compose build
+        //         docker-compose up -d
+        //         '''
+        //     }
+        // }
 
         // stage('Push Docker Image (Nexus)') {
         //     when {
@@ -89,26 +89,27 @@ pipeline {
         //     }
         // }
 
-        stage('Push Docker Image (Nexus)') {
+        stage('Docker Registry Login and Pull') {
     when {
         branch 'master'
     }
     steps {
-        withDockerRegistry([credentialsId: 'nexus', url: 'nexus.foodgame.fr:8123']) {
-            script {
-                def dockerImageName = 'fatboar_master_express_preprod '
-                def dockerImageTag = 'latest'
-                def nexusRepository = 'fatboar_repo'
-
+        script {
+            def registryUrl = 'nexus.foodgame.fr:8123'
+            def imageName = 'fatboar_master_apache_preprod'
+
+            withCredentials([usernamePassword(
+                credentialsId: 'nexus-docker-credentials', 
+                usernameVariable: 'DOCKER_USER', 
+                passwordVariable: 'DOCKER_PASS'
+            )]) {
                 sh """
-                    echo "Tagging Docker image..."
-                    docker tag ${dockerImageName}:${dockerImageTag} ${nexusRepository}/${dockerImageName}:${dockerImageTag}
-                    
-                    echo "Pushing to Nexus repository..."
-                    docker push ${nexusRepository}/${dockerImageName}:${dockerImageTag}
-                    
-                    echo "Cleaning up local images..."
-                    docker rmi ${nexusRepository}/${dockerImageName}:${dockerImageTag} || true
+                    docker login ${registryUrl} -u ${DOCKER_USER} -p ${DOCKER_PASS}
+                    docker pull ${registryUrl}/${imageName}:latest || \
+                    docker pull ${registryUrl}/${imageName} || {
+                        echo "Failed to pull image"
+                        exit 1
+                    }
                 """
             }
         }