This commit is contained in:
Ionel Andrei Cataon
2026-02-12 16:36:00 +02:00
parent 77604629d6
commit 04f2f26561
2 changed files with 19 additions and 13 deletions

View File

@@ -12,10 +12,10 @@ def get_quote():
quote = data.get('content') or data.get('advice') or data.get('q') or "Citatul nu a putut fi găsit." quote = data.get('content') or data.get('advice') or data.get('q') or "Citatul nu a putut fi găsit."
author = data.get('author') or data.get('a') or "Autor necunoscut" author = data.get('author') or data.get('a') or "Autor necunoscut"
print("-" * 30)
print(f"CITAT: {quote}") print(f"CITAT: {quote}")
print(f"AUTOR: {author}") print(f"AUTOR: {author}")
print("-" * 30) with open("quote.txt", "w") as f:
f.write(f"📜 *\"{quote}\"* \n\n✍️ **{author}**")
except Exception as e: except Exception as e:
print(f"Eroare la apelarea API-ului: {e}") print(f"Eroare la apelarea API-ului: {e}")
sys.exit(1) sys.exit(1)

View File

@@ -7,19 +7,17 @@ pipeline {
script { script {
dir('project2') { dir('project2') {
sh "docker build -t quotes-app ." sh "docker build -t quotes-app ."
// Linting simplu
sh "docker run --rm quotes-app python -m py_compile famousquotes.py"
} }
} }
} }
} }
stage('Run App') { stage('Run & Save Quote') {
steps { steps {
script { script {
dir('project2') { dir('project2') {
// Folosim --network host și un DNS public pentru a forța ieșirea la internet // Folosim -v $(pwd):/app pentru ca Python să poată scrie quote.txt în folderul proiectului
sh "docker run --rm --network host --dns 8.8.8.8 -e QUOTE_API_URL='https://api.quotable.io/random' quotes-app" sh "docker run --rm --network host -v \$(pwd):/app -e QUOTE_API_URL='https://api.quotable.io/random' quotes-app"
} }
} }
} }
@@ -27,17 +25,25 @@ pipeline {
} }
post { post {
always { success {
script { script {
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa" // Citim fișierul generat de Python din folderul project2
def status = currentBuild.result ?: 'SUCCESS' def messageContent = readFile('project2/quote.txt').trim()
def discordUrl = "URL_UL_TAU_DE_DISCORD"
// Trimitem mesajul formatat
sh """ sh """
curl -X POST -H 'Content-Type: application/json' \ curl -X POST -H 'Content-Type: application/json' \
-d '{"content": "🚀 Build #${env.BUILD_NUMBER} s-a terminat cu status: ${status}"}' \ -d '{"content": "✅ **Citatul Zilei (Build #${env.BUILD_NUMBER})**\\n\\n${messageContent}"}' \
'${discordUrl}' '${discordUrl}'
""" """
} }
} }
failure {
script {
def discordUrl = "URL_UL_TAU_DE_DISCORD"
sh "curl -X POST -H 'Content-Type: application/json' -d '{\"content\": \"❌ **Build #${env.BUILD_NUMBER}** a eșuat. Verifică log-urile din Jenkins!\"}' '${discordUrl}'"
}
}
} }
} }