Files
it_school/project2/jenkinsfile
Ionel Andrei Cataon eb6ab497de u2
2026-02-12 16:26:05 +02:00

54 lines
2.0 KiB
Plaintext

pipeline {
agent any
stages {
stage('Initialize & Notify') {
steps {
script {
// Notificăm imediat ce pornește build-ul
sendDiscordNotification("🚀 **Proiect 2**: Build #${env.BUILD_NUMBER} a început pe ramura develop.")
}
}
}
stage('Lint & Build') {
steps {
script {
dir('project2') {
sh "docker build -t 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}")
}
}
}
}
}
}
// 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}
"""
}