diff --git a/project2/jenkinsfile b/project2/jenkinsfile index abcabdf..e05af8d 100644 --- a/project2/jenkinsfile +++ b/project2/jenkinsfile @@ -2,58 +2,53 @@ pipeline { agent any stages { - stage('Checkout') { - steps { - checkout scm - } - } - - stage('Lint Check') { + stage('Initialize & Notify') { steps { script { - dir('project2') { - echo "🔍 Verificăm sintaxa Python..." - sh "docker build -t lint-test ." - sh "docker run --rm lint-test python -m py_compile famousquotes.py" - } + // Notificăm imediat ce pornește build-ul + sendDiscordNotification("🚀 **Proiect 2**: Build #${env.BUILD_NUMBER} a început pe ramura develop.") } } } - stage('Build & Run') { + stage('Lint & Build') { steps { script { dir('project2') { - echo "🏗️ Construim și rulăm aplicația..." sh "docker build -t quotes-app ." - - /* Folosim --network host pentru a împrumuta conexiunea care a mers la Proiectul 1. - Am schimbat API-ul cu unul extrem de simplu (AdviceSlip) care nu dă erori de SSL. - */ - sh "docker run --rm --network host -e QUOTE_API_URL='https://api.adviceslip.com/advice' quotes-app" + // Linting folosind imaginea construită + sh "docker run --rm quotes-app python -m py_compile famousquotes.py" + } + } + } + } + + stage('Run App') { + steps { + script { + try { + dir('project2') { + // Folosim un API compatibil care returnează cheia 'content' + // și --network host pentru a asigura ieșirea spre Discord ulterior + sh "docker run --rm --network host -e QUOTE_API_URL='http://api.staging.quotable.io/random' quotes-app" + } + sendDiscordNotification("✅ **Proiect 2**: Build #${env.BUILD_NUMBER} finalizat cu succes!") + } catch (Exception e) { + sendDiscordNotification("❌ **Proiect 2**: Build #${env.BUILD_NUMBER} a eșuat la execuție.") + error("Build failed: ${e.message}") } } } } } +} - post { - always { - script { - def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa" - - def result = currentBuild.result ?: 'SUCCESS' - def emoji = (result == 'SUCCESS') ? "✅" : "❌" - - echo "🚀 Trimitere notificare către Discord (Status: ${result})..." - - // Folosim metoda cea mai simplă de curl care a mers la Proiectul 1 - sh """ - curl -X POST -H 'Content-Type: application/json' \ - -d '{"content": "${emoji} **Proiect 2**: Build #${env.BUILD_NUMBER} s-a finalizat cu status: ${result}"}' \ - ${discordUrl} - """ - } - } - } +// Funcție separată pentru a fi siguri că apelul curl este curat +def sendDiscordNotification(String message) { + def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa" + sh """ + curl -X POST -H 'Content-Type: application/json' \ + -d '{"content": "${message}"}' \ + ${discordUrl} + """ } \ No newline at end of file