pipeline { agent any stages { stage('Build & Lint') { steps { script { dir('project2') { sh "docker build --no-cache -t quotes-app ." echo "🔍 Verificăm sintaxa codului..." sh "docker run --rm quotes-app python -m py_compile famousquotes.py" } } } } stage('Run & Extract') { steps { script { dir('project2') { sh "docker rm -f quotes-worker || true" // Rulăm și afișăm log-urile containerului sh "docker run --name quotes-worker --dns 8.8.8.8 quotes-app" sh "docker logs quotes-worker" sh "docker cp quotes-worker:/app/quote.txt ." // DEBUG: Vedem ce e în fișier direct în Jenkins echo "Conținut fișier extras:" sh "cat quote.txt" } } } } } post { always { script { def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa" def quoteContent = "Fișierul cu citate lipsește." if (fileExists('project2/quote.txt')) { quoteContent = readFile('project2/quote.txt').trim() // Escapăm caracterele speciale pentru a nu strica JSON-ul quoteContent = quoteContent.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n') } def resultStatus = currentBuild.result ?: 'SUCCESS' def statusEmoji = (resultStatus == 'SUCCESS') ? "✅" : "⚠️" def header = "${statusEmoji} **Pipeline Finalizat (Build #${env.BUILD_NUMBER})**" sh """ cat << 'EOF' > discord_payload.json { "content": "${header}\\n\\n${quoteContent}" } EOF """ sh "curl -X POST -H 'Content-Type: application/json' --data-binary @discord_payload.json '${discordUrl}'" } } } }