This commit is contained in:
Ionel Andrei Cataon
2026-02-12 16:22:58 +02:00
parent 8b80461677
commit 7f61b029d4

View File

@@ -4,7 +4,6 @@ pipeline {
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
// Descarcă codul din repository
checkout scm checkout scm
} }
} }
@@ -13,8 +12,8 @@ pipeline {
steps { steps {
script { script {
dir('project2') { dir('project2') {
echo "Verificăm sintaxa Python..." echo "🔍 Verificăm sintaxa Python..."
// Construim o imagine de test pentru a rula verificarea în interiorul ei // Construim o imagine de test ca să fim siguri că avem toate dependințele
sh "docker build -t lint-test ." sh "docker build -t lint-test ."
sh "docker run --rm lint-test python -m py_compile famousquotes.py" sh "docker run --rm lint-test python -m py_compile famousquotes.py"
} }
@@ -22,24 +21,14 @@ pipeline {
} }
} }
stage('Build Docker Image') { stage('Build & Run') {
steps { steps {
script { script {
dir('project2') { dir('project2') {
echo "Construim imaginea finală..." echo "🏗️ Construim și rulăm aplicația..."
sh "docker build -t quotes-app ." sh "docker build -t quotes-app ."
} // Folosim API-ul care dă cheia 'content' pe HTTP ca să evităm eroarea SSL sau 'indices'
} sh "docker run --rm -e QUOTE_API_URL='http://api.staging.quotable.io/random' quotes-app"
}
}
stage('Run & Test API') {
steps {
script {
dir('project2') {
echo "Rulăm aplicația..."
// Folosim un API care returnează obiect (nu listă) pentru a evita eroarea 'indices must be integers'
sh "docker run --rm -e QUOTE_API_URL='https://api.adviceslip.com/advice' quotes-app"
} }
} }
} }
@@ -50,20 +39,18 @@ pipeline {
always { always {
script { script {
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa" def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJwk38mqa"
def status = currentBuild.result ?: 'SUCCESS'
def emoji = (status == 'SUCCESS') ? "✅" : "❌"
// Stabilim statusul pentru mesaj writeFile file: 'discord.json', text: """
def status = currentBuild.result == 'SUCCESS' ? "✅ SUCCESS" : "❌ FAILED"
// Scriem payload-ul într-un fișier pentru a evita problemele cu ghilimelele în shell
writeFile file: 'discord_payload.json', text: """
{ {
"content": "$status: Build #${env.BUILD_NUMBER} s-a finalizat pe branch-ul develop." "content": "$emoji **Build #${env.BUILD_NUMBER}** s-a finalizat cu status: **$status**"
} }
""" """
echo "Trimitere notificare Discord..." echo "🚀 Trimitere notificare către Discord..."
// Trimitem fișierul JSON direct cu curl // Adăugăm -v pentru a vedea în consolă dacă rețeaua blochează Discord-ul
sh "curl -X POST -H 'Content-Type: application/json' -d @discord_payload.json '${discordUrl}'" sh "curl -v -X POST -H 'Content-Type: application/json' -d @discord.json '${discordUrl}'"
} }
} }
} }