pj2
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import requests
|
||||
import os
|
||||
import sys
|
||||
|
||||
API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random")
|
||||
|
||||
def get_quote():
|
||||
try:
|
||||
response = requests.get(API_URL, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# Dacă API-ul returnează o listă (ca ZenQuotes), luăm primul element
|
||||
if isinstance(data, list):
|
||||
data = data[0]
|
||||
|
||||
# Căutăm citatul și autorul în mai multe locuri posibile
|
||||
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: {data['content']}")
|
||||
print(f"AUTOR: {data['author']}")
|
||||
print(f"CITAT: {quote}")
|
||||
print(f"AUTOR: {author}")
|
||||
print("-" * 30)
|
||||
except Exception as e:
|
||||
print(f"Eroare la apelarea API-ului: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_quote()
|
||||
@@ -2,21 +2,12 @@ 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ă
|
||||
// Linting simplu
|
||||
sh "docker run --rm quotes-app python -m py_compile famousquotes.py"
|
||||
}
|
||||
}
|
||||
@@ -26,29 +17,27 @@ pipeline {
|
||||
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}")
|
||||
}
|
||||
// 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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"
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
def discordUrl = "https://discord.com/api/webhooks/1471492658336891013/T5s6ZKZjJjDMHXc3k3jjZdk6m5EV12bKF1wda9d5I_gZJrsDZQ1m1m078IiLJWK38mqa"
|
||||
def status = currentBuild.result ?: 'SUCCESS'
|
||||
|
||||
sh """
|
||||
curl -X POST -H 'Content-Type: application/json' \
|
||||
-d '{"content": "${message}"}' \
|
||||
${discordUrl}
|
||||
-d '{"content": "🚀 Build #${env.BUILD_NUMBER} s-a terminat cu status: ${status}"}' \
|
||||
'${discordUrl}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user