diff --git a/Jenkinsfile b/Jenkinsfile index 793d4899..09585fcd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,53 +1,67 @@ pipeline { - agent any + agent any - environment { - REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr' - BACK_IMAGE = "${REGISTRY}/the-tip-top-backend" + environment { + REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr' + BACK_IMAGE = "${REGISTRY}/the-tip-top-backend" + } + + stages { + + stage('Checkout') { + steps { + git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git' + } } - stages { - stage('Checkout') { - steps { - git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git' - } - } + stage('Build Backend Image') { + steps { + sh ''' + echo "📩 Installation des dĂ©pendances..." + npm install - stage('Build Backend') { - steps { - sh ''' - npm ci - npm run build || true - docker build -t $BACK_IMAGE:latest . - ''' - } - } - - stage('Push Image') { - steps { - sh ''' - docker login $REGISTRY -u $REGISTRY_USER -p $REGISTRY_PASS - docker push $BACK_IMAGE:latest - ''' - } - } - - stage('Deploy Backend') { - steps { - sshagent(['vps-ssh-key']) { - sh ''' - ssh debian@51.75.24.29 " - cd /srv/devops/the-tip-top && - docker compose up -d --build backend - " - ''' - } - } - } + echo "🐳 Construction de l’image Docker backend..." + docker build -t $BACK_IMAGE:latest . + ''' + } } - post { - success { echo "✅ Backend dĂ©ployĂ© avec succĂšs" } - failure { echo "❌ Échec du pipeline Backend" } + stage('Push Image to Registry') { + steps { + withCredentials([usernamePassword(credentialsId: 'gitea-registry', usernameVariable: 'USER', passwordVariable: 'PASS')]) { + sh ''' + echo "🔑 Connexion au registre..." + docker login $REGISTRY -u $USER -p $PASS + + echo "đŸ“€ Push de l’image vers le registre..." + docker push $BACK_IMAGE:latest + ''' + } + } } + + stage('Deploy Backend on VPS') { + steps { + sshagent(['vps-ssh-key']) { + sh ''' + echo "🚀 DĂ©ploiement du backend sur le VPS..." + ssh -o StrictHostKeyChecking=no debian@51.75.24.29 " + cd /srv/devops/the-tip-top && + docker compose pull backend && + docker compose up -d --build backend + " + ''' + } + } + } + } + + post { + success { + echo "✅ Backend dĂ©ployĂ© avec succĂšs !" + } + failure { + echo "❌ Échec du pipeline Backend — vĂ©rifier les logs Jenkins." + } + } }