pj2
This commit is contained in:
@@ -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."
|
||||
author = data.get('author') or data.get('a') or "Autor necunoscut"
|
||||
|
||||
print("-" * 30)
|
||||
print(f"CITAT: {quote}")
|
||||
print(f"AUTOR: {author}")
|
||||
print("-" * 30)
|
||||
with open("quote.txt", "w") as f:
|
||||
f.write(f"📜 *\"{quote}\"* \n\n✍️ **{author}**")
|
||||
except Exception as e:
|
||||
print(f"Eroare la apelarea API-ului: {e}")
|
||||
sys.exit(1)
|
||||
@@ -7,19 +7,17 @@ pipeline {
|
||||
script {
|
||||
dir('project2') {
|
||||
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 {
|
||||
script {
|
||||
dir('project2') {
|
||||
// Folosim --network host și un DNS public pentru a forța ieșirea la internet
|
||||
sh "docker run --rm --network host --dns 8.8.8.8 -e QUOTE_API_URL='https://api.quotable.io/random' quotes-app"
|
||||
// Folosim -v $(pwd):/app pentru ca Python să poată scrie quote.txt în folderul proiectului
|
||||
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 {
|
||||
always {
|
||||
success {
|
||||
script {
|
||||
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa"
|
||||
def status = currentBuild.result ?: 'SUCCESS'
|
||||
// Citim fișierul generat de Python din folderul project2
|
||||
def messageContent = readFile('project2/quote.txt').trim()
|
||||
def discordUrl = "URL_UL_TAU_DE_DISCORD"
|
||||
|
||||
// Trimitem mesajul formatat
|
||||
sh """
|
||||
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}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
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}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user