This commit is contained in:
Ionel Andrei Cataon
2026-02-12 17:17:23 +02:00
parent 2e1da76f1f
commit 0f0f706960
2 changed files with 20 additions and 35 deletions

View File

@@ -1,63 +1,48 @@
pipeline {
agent any
stages {
stage('Build & Lint') {
stage('Build') {
steps {
script {
dir('project2') {
// Folosim --no-cache ca să fim siguri că ia noul Python
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') {
stage('Run') {
steps {
script {
dir('project2') {
sh "docker rm -f quotes-worker || true"
// Rulăm și afișăm log-urile containerului
// Testăm rețeaua înainte de rulare
sh "docker run --rm --dns 8.8.8.8 alpine ping -c 2 google.com || echo 'Internet indisponibil'"
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."
def quoteContent = "Eroare la citirea fișierului."
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}"
"content": "✅ **Pipeline Finalizat (Build #${env.BUILD_NUMBER})**\\n\\n${quoteContent}"
}
EOF
"""
sh "curl -X POST -H 'Content-Type: application/json' --data-binary @discord_payload.json '${discordUrl}'"
}
}