This commit is contained in:
Ionel Andrei Cataon
2026-02-12 16:26:05 +02:00
parent 13c9543797
commit eb6ab497de

View File

@@ -2,58 +2,53 @@ pipeline {
agent any agent any
stages { stages {
stage('Checkout') { stage('Initialize & Notify') {
steps {
checkout scm
}
}
stage('Lint Check') {
steps { steps {
script { script {
dir('project2') { // Notificăm imediat ce pornește build-ul
echo "🔍 Verificăm sintaxa Python..." sendDiscordNotification("🚀 **Proiect 2**: Build #${env.BUILD_NUMBER} a început pe ramura develop.")
sh "docker build -t lint-test ."
sh "docker run --rm lint-test python -m py_compile famousquotes.py"
}
} }
} }
} }
stage('Build & Run') { stage('Lint & Build') {
steps { steps {
script { script {
dir('project2') { dir('project2') {
echo "🏗️ Construim și rulăm aplicația..."
sh "docker build -t quotes-app ." sh "docker build -t quotes-app ."
// Linting folosind imaginea construită
/* Folosim --network host pentru a împrumuta conexiunea care a mers la Proiectul 1. sh "docker run --rm quotes-app python -m py_compile famousquotes.py"
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"
}
} }
} }
} }
} }
post { stage('Run App') {
always { steps {
script { script {
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa" try {
dir('project2') {
def result = currentBuild.result ?: 'SUCCESS' // Folosim un API compatibil care returnează cheia 'content'
def emoji = (result == 'SUCCESS') ? "✅" : "❌" // ș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"
echo "🚀 Trimitere notificare către Discord (Status: ${result})..." }
sendDiscordNotification("✅ **Proiect 2**: Build #${env.BUILD_NUMBER} finalizat cu succes!")
// Folosim metoda cea mai simplă de curl care a mers la Proiectul 1 } catch (Exception e) {
sh """ sendDiscordNotification("❌ **Proiect 2**: Build #${env.BUILD_NUMBER} a eșuat la execuție.")
curl -X POST -H 'Content-Type: application/json' \ error("Build failed: ${e.message}")
-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}
"""
}